Rename config and instance struct to avoid awkward naming

This commit is contained in:
2025-08-04 19:30:50 +02:00
parent 6a7a9a2d09
commit 2abe9c282e
9 changed files with 53 additions and 53 deletions

View File

@@ -10,8 +10,8 @@ import (
"gopkg.in/yaml.v3"
)
// Config represents the configuration for llamactl
type Config struct {
// AppConfig represents the configuration for llamactl
type AppConfig struct {
Server ServerConfig `yaml:"server"`
Instances InstancesConfig `yaml:"instances"`
Auth AuthConfig `yaml:"auth"`
@@ -85,9 +85,9 @@ type AuthConfig struct {
// 1. Hardcoded defaults
// 2. Config file
// 3. Environment variables
func LoadConfig(configPath string) (Config, error) {
func LoadConfig(configPath string) (AppConfig, error) {
// 1. Start with defaults
cfg := Config{
cfg := AppConfig{
Server: ServerConfig{
Host: "0.0.0.0",
Port: 8080,
@@ -126,7 +126,7 @@ func LoadConfig(configPath string) (Config, error) {
}
// loadConfigFile attempts to load config from file with fallback locations
func loadConfigFile(cfg *Config, configPath string) error {
func loadConfigFile(cfg *AppConfig, configPath string) error {
var configLocations []string
// If specific config path provided, use only that
@@ -150,7 +150,7 @@ func loadConfigFile(cfg *Config, configPath string) error {
}
// loadEnvVars overrides config with environment variables
func loadEnvVars(cfg *Config) {
func loadEnvVars(cfg *AppConfig) {
// Server config
if host := os.Getenv("LLAMACTL_HOST"); host != "" {
cfg.Server.Host = host

View File

@@ -271,31 +271,31 @@ func TestLoadConfig_EnvironmentVariableTypes(t *testing.T) {
testCases := []struct {
envVar string
envValue string
checkFn func(*config.Config) bool
checkFn func(*config.AppConfig) bool
desc string
}{
{
envVar: "LLAMACTL_PORT",
envValue: "invalid-port",
checkFn: func(c *config.Config) bool { return c.Server.Port == 8080 }, // Should keep default
checkFn: func(c *config.AppConfig) bool { return c.Server.Port == 8080 }, // Should keep default
desc: "invalid port number should keep default",
},
{
envVar: "LLAMACTL_MAX_INSTANCES",
envValue: "not-a-number",
checkFn: func(c *config.Config) bool { return c.Instances.MaxInstances == -1 }, // Should keep default
checkFn: func(c *config.AppConfig) bool { return c.Instances.MaxInstances == -1 }, // Should keep default
desc: "invalid max instances should keep default",
},
{
envVar: "LLAMACTL_DEFAULT_AUTO_RESTART",
envValue: "invalid-bool",
checkFn: func(c *config.Config) bool { return c.Instances.DefaultAutoRestart == true }, // Should keep default
checkFn: func(c *config.AppConfig) bool { return c.Instances.DefaultAutoRestart == true }, // Should keep default
desc: "invalid boolean should keep default",
},
{
envVar: "LLAMACTL_INSTANCE_PORT_RANGE",
envValue: "invalid-range",
checkFn: func(c *config.Config) bool { return c.Instances.PortRange == [2]int{8000, 9000} }, // Should keep default
checkFn: func(c *config.AppConfig) bool { return c.Instances.PortRange == [2]int{8000, 9000} }, // Should keep default
desc: "invalid port range should keep default",
},
}