package config import ( "os" "gopkg.in/yaml.v2" ) // Config estructura la configuración completa del demonio. type Config struct { Database struct { Host string `yaml:"host"` Port int `yaml:"port"` User string `yaml:"user"` Password string `yaml:"password"` DBName string `yaml:"dbname"` SSLMode string `yaml:"sslmode"` } `yaml:"database"` SOAP struct { APIKey string `yaml:"apikey"` FACTURA_SINCRONIZACION struct { Endpoint string `yaml:"endpoint"` Timeout int `yaml:"timeout"` Retries int `yaml:"retries"` } FACTURA_CODIGO struct { Endpoint string `yaml:"endpoint"` Timeout int `yaml:"timeout"` Retries int `yaml:"retries"` } } `yaml:"soap"` Schedule struct { FACTURA_SINCRONIZACION struct { Cron string `yaml:"cron"` } FACTURA_CODIGO struct { Cron string `yaml:"cron"` } } `yaml:"schedule"` API struct { Port int `yaml:"port"` } `yaml:"api"` Notifications struct { Enabled bool `yaml:"enabled"` Method string `yaml:"method"` // "email", "webhook", "slack", etc. Config map[string]string `yaml:"config"` } `yaml:"notifications"` Services []struct { Name string `yaml:"name"` Enabled bool `yaml:"enabled"` Concurrency int `yaml:"concurrency"` } `yaml:"services"` } // LoadConfig carga la configuración desde el archivo YAML. func LoadConfig(path string) (*Config, error) { f, err := os.Open(path) if err != nil { return nil, err } defer f.Close() var cfg Config decoder := yaml.NewDecoder(f) if err := decoder.Decode(&cfg); err != nil { return nil, err } return &cfg, nil } // package config // import ( // "os" // "gopkg.in/yaml.v2" // ) // // Config estructura global de configuración. // type Config struct { // Database struct { // Host string `yaml:"host"` // Port int `yaml:"port"` // User string `yaml:"user"` // Password string `yaml:"password"` // DBName string `yaml:"dbname"` // SSLMode string `yaml:"sslmode"` // } `yaml:"database"` // SOAP struct { // Endpoint string `yaml:"endpoint"` // Timeout int `yaml:"timeout"` // Retries int `yaml:"retries"` // } `yaml:"soap"` // Schedule struct { // Cron string `yaml:"cron"` // } `yaml:"schedule"` // API struct { // Port int `yaml:"port"` // } `yaml:"api"` // Notifications struct { // Enabled bool `yaml:"enabled"` // Method string `yaml:"method"` // "email", "webhook", "slack", etc. // Config map[string]string `yaml:"config"` // } `yaml:"notifications"` // Services []struct { // Name string `yaml:"name"` // Enabled bool `yaml:"enabled"` // Concurrency int `yaml:"concurrency"` // } `yaml:"services"` // } // // Load carga la configuración a partir de un archivo YAML. // func Load(configFile string) (*Config, error) { // f, err := os.Open(configFile) // if err != nil { // return nil, err // } // defer f.Close() // var cfg Config // decoder := yaml.NewDecoder(f) // if err := decoder.Decode(&cfg); err != nil { // return nil, err // } // return &cfg, nil // }