package config import "github.com/spf13/viper" type Config struct { Server ServerConfig `mapstructure:"server"` } type ServerConfig struct { Port int `mapstructure:"port"` Host string `mapstructure:"host"` } var AppConfig Config func LoadConfig() error { viper.SetConfigName("config") viper.SetConfigType("yaml") viper.AddConfigPath(".") if err := viper.ReadInConfig(); err != nil { return err } if err := viper.Unmarshal(&AppConfig); err != nil { return err } return nil }