36 lines
715 B
Go
36 lines
715 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
var version = os.Getenv("APP_VERSION")
|
|
|
|
type status struct {
|
|
Status string `json:"status"`
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
func main() {
|
|
if version == "" {
|
|
version = "dev"
|
|
}
|
|
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_ = json.NewEncoder(w).Encode(status{Status: "ok", Version: version})
|
|
})
|
|
|
|
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write([]byte("ok"))
|
|
})
|
|
|
|
addr := ":8080"
|
|
log.Printf("listening on %s, version=%s", addr, version)
|
|
log.Fatal(http.ListenAndServe(addr, nil))
|
|
}
|