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
|
FROM quay01.ipa.endofday.com/everythingkubernetes/golang as build-env
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY /go/. .
|
||||||
|
|
||||||
RUN go get -d -v ./...
|
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -o app
|
RUN CGO_ENABLED=0 GOOS=linux go build -o app
|
||||||
|
|
||||||
|
@ -7,10 +7,30 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type HealthcheckResponse struct {
|
||||||
|
Healthcheck string `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
type HostnameResponse struct {
|
type HostnameResponse struct {
|
||||||
Hostname string `json:"hostname"`
|
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) {
|
func getHostnameHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
hostname, err := os.Hostname()
|
hostname, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -34,6 +54,7 @@ func getHostnameHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
http.HandleFunc("/healthz", getHealthcheckHandler)
|
||||||
http.HandleFunc("/api/v1/getHostname", getHostnameHandler)
|
http.HandleFunc("/api/v1/getHostname", getHostnameHandler)
|
||||||
|
|
||||||
port := 8080
|
port := 8080
|
||||||
|
Loading…
Reference in New Issue
Block a user