package core import ( "errors" "os/user" "github.com/spf13/viper" ) // Config will follow this model // server : string // port : int // Load config file func LoadConfig() error { // Get current user currentUser, err := user.Current() if err != nil { // panic("LoadConfig: Failed to retrieve curent user -> " + err.Error()) return err } // Set default values viper.SetDefault("server", "example.com") viper.SetDefault("port", 5660) // Set config paths viper.SetConfigName("config") viper.SetConfigType("json") viper.AddConfigPath("/etc/cosync/") viper.AddConfigPath("/home/" + currentUser.Username + "/.config/cosync") // Read from config files err = viper.ReadInConfig() if err != nil { panic("LoadConfig: Failed to read config file -> " + err.Error()) // return err } return nil } // Generate config folder and files func MkConfig() error { return errors.New("not implemented") } // Load sync list from sync file func LoadSyncList() error { return errors.New("not implemented") } // returns all config variables // ! WARNING: Do not use this function without executing LoadConfig prior func GetConfig() map[string]any { return viper.AllSettings() }