MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / LoadConfig

Function LoadConfig

pkg/mcp/config.go:61–84  ·  view source on GitHub ↗

LoadConfig reads configuration from environment variables, applying defaults for any variables that are unset or empty.

()

Source from the content-addressed store, hash-verified

59// LoadConfig reads configuration from environment variables, applying defaults
60// for any variables that are unset or empty.
61func LoadConfig() (*Config, error) {
62 cfg := DefaultConfig()
63
64 if v := os.Getenv("GOSQLX_MCP_HOST"); v != "" {
65 cfg.Host = v
66 }
67
68 if v := os.Getenv("GOSQLX_MCP_PORT"); v != "" {
69 port, err := strconv.Atoi(v)
70 if err != nil {
71 return nil, fmt.Errorf("GOSQLX_MCP_PORT: expected integer, got %q", v)
72 }
73 if port < 1 || port > 65535 {
74 return nil, fmt.Errorf("GOSQLX_MCP_PORT: %d is out of range (1–65535)", port)
75 }
76 cfg.Port = port
77 }
78
79 if v := strings.TrimSpace(os.Getenv("GOSQLX_MCP_AUTH_TOKEN")); v != "" {
80 cfg.AuthToken = v
81 }
82
83 return cfg, nil
84}
85
86// DefaultConfig returns a Config with all defaults applied (auth disabled).
87func DefaultConfig() *Config {

Callers 5

TestLoadConfig_DefaultsFunction · 0.70
TestLoadConfig_AuthTokenFunction · 0.70

Calls 2

DefaultConfigFunction · 0.70
ErrorfMethod · 0.65

Tested by 5

TestLoadConfig_DefaultsFunction · 0.56
TestLoadConfig_AuthTokenFunction · 0.56