I'm writing a small program in Go to check a server's status is up (out of a list of servers) by hostname. I have a function that iterates over a server type once they're all retrieved and stored from an http.GET into slice of type server.
I can log (commented out below) and see that both of these evaluate correctly:
// fmt.Printf("Server: %s - Status: %s\n", server.Name, status)
// fmt.Printf("%t\n", name == strings.ToLower(server.Name))
Both have the expected outcome but when I run the program, the fmt.Printf()
call inside the if statement does not print to the console.
func getServerStatus(name string) {
servers := getAllServers()
for _, server := range servers {
status := boolToStatusString(server.Status)
// fmt.Printf("Server: %s - Status: %s\n", server.Name, status)
// fmt.Printf("%t\n", name == strings.ToLower(server.Name))
if server.Name == strings.ToLower(name) {
fmt.Printf("%s is %s", name, status)
}
}
}
I've tried running this function as a goroutine
with a channel
of type string
to store the result and call the Printf
outside this function but anytime I go run main.go
it just executes and prints nothing.
Solved: evaluating both as strings.ToLower in the if statement resolved the issue.