linter improvements

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2024-05-28 15:39:27 +02:00
parent 58aaec4d59
commit b8f39cd604
No known key found for this signature in database

View File

@ -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
} }