Updated go module with healthcheck
This commit is contained in:
parent
e86a906f28
commit
6e766a78a5
@ -1,9 +1,7 @@
|
||||
FROM quay01.ipa.endofday.com/everythingkubernetes/golang as build-env
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
||||
RUN go get -d -v ./...
|
||||
COPY /go/. .
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o app
|
||||
|
||||
|
@ -7,10 +7,30 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type HealthcheckResponse struct {
|
||||
Healthcheck string `json:"status"`
|
||||
}
|
||||
|
||||
type HostnameResponse struct {
|
||||
Hostname string `json:"hostname"`
|
||||
}
|
||||
|
||||
func getHealthcheckHandler(w http.ResponseWriter, r *http.Request) {
|
||||
response := HealthcheckResponse{
|
||||
Healthcheck: "healthy",
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
http.Error(w, "Error encoding response", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(jsonData)
|
||||
}
|
||||
|
||||
func getHostnameHandler(w http.ResponseWriter, r *http.Request) {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
@ -34,6 +54,7 @@ func getHostnameHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/healthz", getHealthcheckHandler)
|
||||
http.HandleFunc("/api/v1/getHostname", getHostnameHandler)
|
||||
|
||||
port := 8080
|
||||
|
Loading…
Reference in New Issue
Block a user