package config import ( "os" "gopkg.in/yaml.v3" ) type Config struct { Token TokenConfig `yaml:"token" json:"token"` Server ServerConfig `yaml:"server" json:"server"` DB DatabaseConfig `yaml:"db" json:"db"` } type ServerConfig struct { Port string `yaml:"port" json:"port"` } type DatabaseConfig struct { Username string `yaml:"username" json:"username"` Host string `yaml:"host" json:"host"` Port string `yaml:"port" json:"port"` Sslmode string `yaml:"sslmode" json:"sslmode"` DBname string `yaml:"dbname" json:"dbname"` } func LoadConfig(absolutePath string) (*Config, error) { config := &Config{} file, err := os.Open(absolutePath) if err != nil { return nil, err } defer file.Close() decoder := yaml.NewDecoder(file) if err := decoder.Decode(config); err != nil { return nil, err } return config, nil }