mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-07-10 14:32:31 +00:00
linter improvements
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
58aaec4d59
commit
b8f39cd604
@ -1,9 +1,9 @@
|
|||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@ -222,9 +222,10 @@ func IsLegitMachineAddress(address string) (active bool, err error) {
|
|||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
||||||
// Create a new request
|
// Create a new request
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
ctx := context.Background()
|
||||||
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Println("[app] [Monitor] cannot send machine query request " + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +259,7 @@ func IsLegitMachineAddress(address string) (active bool, err error) {
|
|||||||
var data map[string]interface{}
|
var data map[string]interface{}
|
||||||
err = json.Unmarshal(body, &data)
|
err = json.Unmarshal(body, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Println("[app] [Monitor] cannot unmarshal response " + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,14 +269,18 @@ func IsLegitMachineAddress(address string) (active bool, err error) {
|
|||||||
log.Println("[app] [Monitor] response does not contain the required machine")
|
log.Println("[app] [Monitor] response does not contain the required machine")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
machineMap := machineValue.(map[string]interface{})
|
machineMap, ok := machineValue.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
log.Println("[app] [Monitor] cannot convert machine map")
|
||||||
|
return
|
||||||
|
}
|
||||||
nameMap, ok := machineMap["name"]
|
nameMap, ok := machineMap["name"]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("[app] [Monitor] response does not contain the required name")
|
log.Println("[app] [Monitor] response does not contain the required name")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
value, ok := nameMap.(string)
|
||||||
if nameMap.(string) != address {
|
if !ok || value != address {
|
||||||
log.Println("[app] [Monitor] return machine is not the required one")
|
log.Println("[app] [Monitor] return machine is not the required one")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user