From 2691ded81905cc41e264fcdc4c41ddffa793870a Mon Sep 17 00:00:00 2001 From: acty Date: Tue, 3 Feb 2026 18:01:23 +0900 Subject: [PATCH] feat(01-01): initialize Go project with HTTP server - Go module initialized with github.com/acty/pirate-station - HTTP server on port 32768 with root and health endpoints - Health check verifies /data volume mount - No external dependencies, stdlib only --- cmd/server/main.go | 27 +++++++++++++++++++++++++++ go.mod | 3 +++ internal/health/handler.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 cmd/server/main.go create mode 100644 go.mod create mode 100644 internal/health/handler.go diff --git a/cmd/server/main.go b/cmd/server/main.go new file mode 100644 index 0000000..0cc7d88 --- /dev/null +++ b/cmd/server/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "log" + "net/http" + + "github.com/acty/pirate-station/internal/health" +) + +func main() { + // Root endpoint + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("Pirate Station API")) + }) + + // Health check endpoint + http.HandleFunc("/health", health.Handler) + + // Start server on port 32768 + port := ":32768" + log.Printf("Starting Pirate Station server on port %s", port) + + if err := http.ListenAndServe(port, nil); err != nil { + log.Fatal(err) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..baf0e09 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/acty/pirate-station + +go 1.19 diff --git a/internal/health/handler.go b/internal/health/handler.go new file mode 100644 index 0000000..6e6427c --- /dev/null +++ b/internal/health/handler.go @@ -0,0 +1,28 @@ +package health + +import ( + "encoding/json" + "net/http" + "os" +) + +// Handler provides a health check endpoint that verifies the data volume is mounted +func Handler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + + // Check if /data directory exists + if _, err := os.Stat("/data"); os.IsNotExist(err) { + w.WriteHeader(http.StatusServiceUnavailable) + json.NewEncoder(w).Encode(map[string]string{ + "status": "unhealthy", + "reason": "data volume not mounted", + }) + return + } + + // All checks passed + w.WriteHeader(http.StatusOK) + json.NewEncoder(w).Encode(map[string]string{ + "status": "healthy", + }) +}