Files
ttstd-infinite-canvas/backend/cmd/server/fork_env.go

29 lines
968 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 本项目附加文件(fork 专属):不改上游 main.go,达到同样的启动行为。
// 独立成一个文件后,上游对同目录 main.go 的任何改动都不会再与本文件冲突。
package main
import (
"log"
"os"
"strings"
"yingce/backend/internal/config"
)
func init() {
config.LoadDotEnv()
// 本地开发默认绑定 127.0.0.1:7381(见 AGENTS.md「本项目附加约定」)。
// 显式配置优先,例如 Compose 注入的 CANVAS_BACKEND_ADDR=":8080" 不会被覆盖。
if strings.TrimSpace(os.Getenv("CANVAS_BACKEND_ADDR")) == "" {
_ = os.Setenv("CANVAS_BACKEND_ADDR", "127.0.0.1:7381")
}
// 启动诊断:确认 .env / 环境变量已被读到,避免误用空 DATABASE_URL 时的静默回退。
dbURLState := "empty"
if strings.TrimSpace(os.Getenv("DATABASE_URL")) != "" {
dbURLState = "set"
}
log.Printf("fork-env: CANVAS_BACKEND_ADDR=%s, DATABASE_URL=%s", os.Getenv("CANVAS_BACKEND_ADDR"), dbURLState)
}