chore: configure gin mode
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
2bdad13e5c
commit
ab4f905725
@@ -15,6 +15,7 @@ type Config struct {
|
||||
Workspace WorkspaceConfig `yaml:"workspace"`
|
||||
Process ProcessConfig `yaml:"process"`
|
||||
File FileConfig `yaml:"file"`
|
||||
Gin GinConfig `yaml:"gin"`
|
||||
Log LogConfig `yaml:"log"`
|
||||
}
|
||||
|
||||
@@ -42,6 +43,11 @@ type FileConfig struct {
|
||||
MaxWriteBytes int64 `yaml:"maxWriteBytes"`
|
||||
}
|
||||
|
||||
// GinConfig holds Gin framework runtime settings.
|
||||
type GinConfig struct {
|
||||
Mode string `yaml:"mode"`
|
||||
}
|
||||
|
||||
// LogConfig holds structured logging settings.
|
||||
type LogConfig struct {
|
||||
Level string `yaml:"level"`
|
||||
@@ -55,6 +61,7 @@ type rawConfig struct {
|
||||
Workspace WorkspaceConfig `yaml:"workspace"`
|
||||
Process ProcessConfig `yaml:"process"`
|
||||
File FileConfig `yaml:"file"`
|
||||
Gin GinConfig `yaml:"gin"`
|
||||
Log LogConfig `yaml:"log"`
|
||||
}
|
||||
|
||||
@@ -79,6 +86,7 @@ func Default() Config {
|
||||
Workspace: WorkspaceConfig{Root: "./workspaces"},
|
||||
Process: ProcessConfig{OpenCodeCommand: "opencode"},
|
||||
File: FileConfig{MaxWriteBytes: 1 << 20},
|
||||
Gin: GinConfig{Mode: "release"},
|
||||
Log: LogConfig{Level: "info", Format: "json"},
|
||||
}
|
||||
}
|
||||
@@ -104,6 +112,9 @@ func Load(path string) (Config, error) {
|
||||
if err := applyEnv(&cfg); err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
if err := validateGinMode(cfg.Gin.Mode); err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
@@ -132,6 +143,9 @@ func applyRaw(cfg *Config, raw rawConfig) error {
|
||||
if raw.File.MaxWriteBytes != 0 {
|
||||
cfg.File.MaxWriteBytes = raw.File.MaxWriteBytes
|
||||
}
|
||||
if raw.Gin.Mode != "" {
|
||||
cfg.Gin.Mode = raw.Gin.Mode
|
||||
}
|
||||
if raw.Log.Level != "" {
|
||||
cfg.Log.Level = raw.Log.Level
|
||||
}
|
||||
@@ -192,6 +206,9 @@ func applyEnv(cfg *Config) error {
|
||||
}
|
||||
cfg.File.MaxWriteBytes = n
|
||||
}
|
||||
if v := os.Getenv("CODESPACE_GIN_MODE"); v != "" {
|
||||
cfg.Gin.Mode = v
|
||||
}
|
||||
if v := os.Getenv("CODESPACE_LOG_LEVEL"); v != "" {
|
||||
cfg.Log.Level = v
|
||||
}
|
||||
@@ -200,3 +217,12 @@ func applyEnv(cfg *Config) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateGinMode(mode string) error {
|
||||
switch mode {
|
||||
case "debug", "release", "test":
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid gin mode %q: must be one of debug, release, test", mode)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user