fix(issue-9): No Dockerfile to build service

This commit is contained in:
frx
2026-07-01 17:06:02 +00:00
parent 6d6f5e19d1
commit c2cefe0d32
5 changed files with 124 additions and 0 deletions

28
cmd/healthcheck/main.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"fmt"
"net/http"
"os"
"time"
)
func main() {
url := "http://127.0.0.1:8080/healthz"
if len(os.Args) > 1 {
url = os.Args[1]
}
client := &http.Client{Timeout: 3 * time.Second}
resp, err := client.Get(url)
if err != nil {
fmt.Fprintf(os.Stderr, "healthcheck error: %v\n", err)
os.Exit(1)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
fmt.Fprintf(os.Stderr, "healthcheck failed: status %s\n", resp.Status)
os.Exit(1)
}
}

View File

@ -63,6 +63,11 @@ func setupHTTP(cfg config.HTTP, srv xhttp.Server, log *slog.Logger) *http.Server
middlewareMetrics(),
)
router.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
}).Methods(http.MethodGet)
setupCoursesHTTP(srv, router, log)
if cfg.MountLive {