diff --git a/.gitignore b/.gitignore index 0ecf443..d90b205 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,7 @@ Thumbs.db !.env.example # Local-only working notes (use task board for shared tracking) -TODO.md \ No newline at end of file +TODO.md + +# Release artifacts (build output) +release/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 95f50e1..18a4b54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN apk --no-cache add ca-certificates tzdata \ WORKDIR /app COPY --from=builder /app/tts-api . -COPY --from=builder /app/health.html . +# health.html 已通过 //go:embed 嵌入 binary,无需单独复制 RUN chown -R appuser:appgroup /app diff --git a/main.go b/main.go index 25dc991..27674ab 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,6 @@ func main() { setting.InitAllConfigs() metrics.Init() middleware.InitRateLimiter() - setting.CheckStaticFiles() controller.InitController() setting.LogStartupSummary() diff --git a/router/dashboard.go b/router/dashboard.go new file mode 100644 index 0000000..43d1f25 --- /dev/null +++ b/router/dashboard.go @@ -0,0 +1,6 @@ +package router + +import _ "embed" + +//go:embed health.html +var dashboardHTML []byte \ No newline at end of file diff --git a/health.html b/router/health.html similarity index 100% rename from health.html rename to router/health.html diff --git a/router/router.go b/router/router.go index e06a38d..14bda65 100644 --- a/router/router.go +++ b/router/router.go @@ -20,7 +20,8 @@ func Setup() *mux.Router { r.HandleFunc("/v1/audio/speech", controller.OpenaiTTSHandler).Methods("POST", "OPTIONS") r.HandleFunc("/health", controller.HealthHandler).Methods("GET") r.HandleFunc("/dashboard", func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "health.html") + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.Write(dashboardHTML) }).Methods("GET") r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/dashboard", http.StatusFound) diff --git a/setting/config.go b/setting/config.go index 38ea45f..da957d2 100644 --- a/setting/config.go +++ b/setting/config.go @@ -309,10 +309,3 @@ func maskAPIKey(key string) string { } return key[:4] + "****" + key[len(key)-4:] } - -// CheckStaticFiles 检查 /dashboard 路由依赖的 health.html 是否存在。 -func CheckStaticFiles() { - if _, err := os.Stat("health.html"); os.IsNotExist(err) { - log.Println("警告: health.html 不存在,/dashboard 路由将返回 404") - } -}