Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
Created February 18, 2019 23:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timjonesdev/c4a7a1f75c62a31cbc1d35ed67f44a88 to your computer and use it in GitHub Desktop.
Save timjonesdev/c4a7a1f75c62a31cbc1d35ed67f44a88 to your computer and use it in GitHub Desktop.
A simple health check Go application
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