feat(config): support cli config path and nested config
All checks were successful
CI / Lint (pull_request) Successful in 5s
CI / Test (pull_request) Successful in 8s
CI / Build (pull_request) Successful in 7s
CI / Docker Build (pull_request) Successful in 23s

Adds -config CLI flag to main.go. Moves ParseLogLevel to internal/config. Adds ServerConfig nested struct to Config and corresponding tests for yaml/env overrides.
This commit is contained in:
Gemini CLI
2026-01-15 18:37:01 +00:00
parent 6623ced227
commit ec689c6152
3 changed files with 79 additions and 20 deletions

View File

@@ -2,11 +2,11 @@ package main
import (
"context"
"flag"
"fmt"
"log/slog"
"os"
"os/signal"
"strings"
"syscall"
"time"
@@ -14,8 +14,13 @@ import (
)
func main() {
// Parse CLI flags
var configPath string
flag.StringVar(&configPath, "config", "config/config.yaml", "path to config file")
flag.Parse()
// Load Configuration
cfg, err := config.Load("config/config.yaml", "APP")
cfg, err := config.Load(configPath, "APP")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load config: %v\n", err)
os.Exit(1)
@@ -23,7 +28,7 @@ func main() {
// Setup Logger
opts := &slog.HandlerOptions{
Level: parseLogLevel(cfg.LogLevel),
Level: config.ParseLogLevel(cfg.LogLevel),
}
logger := slog.New(slog.NewJSONHandler(os.Stdout, opts))
slog.SetDefault(logger)
@@ -46,21 +51,6 @@ func main() {
}
}
func parseLogLevel(level string) slog.Level {
switch strings.ToLower(level) {
case "debug":
return slog.LevelDebug
case "info":
return slog.LevelInfo
case "warn":
return slog.LevelWarn
case "error":
return slog.LevelError
default:
return slog.LevelInfo
}
}
func run(ctx context.Context) error {
slog.Info("Starting application...")