Files
pgproxy/app/config/config.go
Björn Benouarets c6b269cf35 init: Initial commit
2025-12-15 14:13:43 +01:00

38 lines
834 B
Go

package config
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
)
// Config represents the proxy configuration
type Config struct {
Listen struct {
Address string `yaml:"address"`
Port int `yaml:"port"`
} `yaml:"listen"`
Mappings []struct {
External string `yaml:"external"`
Internal string `yaml:"internal"`
Port int `yaml:"port"` // Optional, defaults to listen port
} `yaml:"mappings"`
Debug bool `yaml:"debug"`
}
// loadConfig loads configuration from YAML file
func LoadConfig(configPath string) (*Config, error) {
data, err := os.ReadFile(configPath)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
}
var config Config
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, fmt.Errorf("failed to parse config file: %w", err)
}
return &config, nil
}