Created
February 18, 2019 23:50
-
-
Save timjonesdev/c4a7a1f75c62a31cbc1d35ed67f44a88 to your computer and use it in GitHub Desktop.
A simple health check Go application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"os" | |
) | |
func main() { | |
// Could/should make this configurable | |
resp, err := http.Get("http://localhost:8080/health") | |
fmt.Printf("Response Status: %v", resp.StatusCode) | |
fmt.Println("") | |
fmt.Println("...") | |
if err != nil { | |
fmt.Println("Error: Service Not Healthy") | |
os.Exit(1) | |
} | |
// os.Exit(0) - happy | |
if resp.StatusCode == http.StatusOK { | |
fmt.Println("Service is Alive and Healthy") | |
os.Exit(0) | |
} | |
// os.Exit(1) - sad | |
fmt.Println("Service Not healthy") | |
os.Exit(1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment