Spaces:
Runtime error
Runtime error
| package utils | |
| import ( | |
| "log" | |
| "os" | |
| "gopkg.in/ini.v1" | |
| ) | |
| type Config struct { | |
| Server ServerConfig `ini:"server"` | |
| Client ClientConfig `ini:"client"` | |
| Proxy ProxyConfig `ini:"proxy"` | |
| } | |
| type ServerConfig struct { | |
| BindAddr string `ini:"bind_addr"` | |
| BindPort int `ini:"bind_port"` | |
| PrivateKeyPath string `ini:"private_key_path"` | |
| } | |
| type ClientConfig struct { | |
| ServerAddr string `ini:"server_addr"` | |
| ServerPort int `ini:"server_port"` | |
| PrivateKeyPath string `ini:"private_key_path"` | |
| } | |
| type ProxyConfig struct { | |
| LocalAddr string `ini:"local_addr"` | |
| LocalPort int `ini:"local_port"` | |
| ProxyType string `ini:"proxy_type"` | |
| ProxyName string `ini:"proxy_name"` | |
| EncryptionEnabled bool `ini:"encryption_enabled"` | |
| } | |
| func LoadConfig() *Config { | |
| cfg, err := ini.Load("config.ini") | |
| if err != nil { | |
| log.Fatalf("Failed to read config file: %v", err) | |
| os.Exit(1) | |
| } | |
| config := &Config{} | |
| err = cfg.MapTo(config) | |
| if err != nil { | |
| log.Fatalf("Failed to parse config file: %v", err) | |
| os.Exit(1) | |
| } | |
| return config | |
| } |