package main import ( "fmt" "os" "path/filepath" "github.com/spf13/viper" ) type Config struct { SSHUser string `mapstructure:"SSH_USER"` SSHHost string `mapstructure:"SSH_HOST"` JumpUser string `mapstructure:"JUMP_USER"` JumpHost string `mapstructure:"JUMP_HOST"` WorkstationHost string `mapstructure:"WORKSTATION_HOST"` WorkstationUser string `mapstructure:"WORKSTATION_USER"` WorkstationMac string `mapstructure:"WORKSTATION_MAC"` RDPUser string `mapstructure:"RDP_USER"` RDPPassword string `mapstructure:"RDP_PASSWORD"` WorkstationIP string `mapstructure:"WORKSTATION_IP"` SSHPort int `mapstructure:"SSH_PORT"` } type Flags struct { ShowWeek bool ShowMonth bool ShowExport bool } func loadConfig() (Config, error) { var cfg Config configPath, err := os.UserConfigDir() if err != nil { return cfg, err } workConfigPath := filepath.Join(configPath, "work") configFile := filepath.Join(workConfigPath, "config.toml") viper.SetConfigFile(configFile) viper.SetConfigType("toml") viper.AddConfigPath(".") viper.AutomaticEnv() if err := viper.ReadInConfig(); err != nil { return cfg, fmt.Errorf("error reading config file: %w", err) } if err := viper.UnmarshalKey("default", &cfg); err != nil { return cfg, fmt.Errorf("error decoding config: %w", err) } return cfg, nil }