refactor!: move every config default into compose.yml

compose.yml now holds each default as ${VAR:-default}, and the code keeps
no fallback values. The bot stops at startup on a missing or invalid
PORT or LOG_LEVEL, /addsticker refuses without STICKER_PACK_NAME, and the
renderer refuses to start until every RENDERER_* setting is a valid
value, listing each problem. Settings whose empty value means none or
all (MODULES, OWNER_ID, ADMIN_IDS, the API tokens) use ${VAR:-}.

The renderer's npm start and dev load .env when present, so a local run
works from a copy of .env.example.

BREAKING CHANGE: running outside compose now requires LOG_LEVEL and PORT
for the bot, STICKER_PACK_NAME for /addsticker, and every RENDERER_*
variable for the renderer.
This commit is contained in:
tiennm99 committed 2026-10-03 12:38:39 +07:00
1 parent 4f8c01dae7
commit 153fc211cf
17 files changed
+208 -94

No files matched your search

+9 -7
View File
@@ -368,9 +368,9 @@ type config struct {
MongoDatabase string // required when KVProvider=mongodb
}
// loadConfig reads config from the environment. PORT defaults to 8080 and an
// invalid PORT is fatal; malformed OWNER_ID / ADMIN_IDS entries are logged and
// ignored.
// loadConfig reads config from the environment. compose.yml supplies every
// default, so the code keeps none: a missing or invalid PORT or LOG_LEVEL is
// fatal. Malformed OWNER_ID / ADMIN_IDS entries are logged and ignored.
func loadConfig() config {
envMap := make(map[string]string, len(os.Environ()))
for _, kv := range os.Environ() {
@@ -378,15 +378,17 @@ func loadConfig() config {
envMap[kv[:eq]] = kv[eq+1:]
}
}
port := envMap["PORT"]
if port == "" {
port = "8080"
level, err := log.ParseLevel(envMap["LOG_LEVEL"])
if err != nil {
log.Fatal("invalid LOG_LEVEL", "err", err)
}
log.SetLevel(level)
port := strings.TrimSpace(envMap["PORT"])
// PORT must be a number in 0..65535. http.Server uses ":<port>" verbatim,
// so a junk value would otherwise surface only at ListenAndServe time;
// fail fast here instead.
if n, err := strconv.Atoi(port); err != nil || n < 0 || n > 65535 {
log.Fatal("invalid PORT", "value", port)
log.Fatal("missing or invalid PORT", "value", port)
}
return config{
Port: port,