Initial work on parsing config file

This commit is contained in:
Dan Jones 2023-03-23 13:03:16 -05:00
commit 996f59c8af
4 changed files with 51 additions and 4 deletions

39
config/config.go Normal file
View file

@ -0,0 +1,39 @@
package config
import (
"github.com/BurntSushi/toml"
"github.com/kirsle/configdir"
"path/filepath"
)
type Config struct {
Domain string `toml:"domain"`
Username string `toml:"username"`
Password string `toml:"admin_password"`
Name string `toml:"name"`
Summary string `toml:"summary"`
Https bool `toml:"https"`
IconUrl string `toml:"icon_url""`
ImageUrl string `toml:"image_url"`
Secret string `toml:"secret"`
TrustedHosts []string `toml:"trusted_hosts"`
ManuallyApproveFollers bool `toml:"manually_approves_followers"`
}
var config Config
func init() {
configPath := configdir.LocalConfig("gopub")
if err := configdir.MakePath(configPath); err != nil {
panic(err)
}
configFile := filepath.Join(configPath, "profile.toml")
if _, err := toml.DecodeFile(configFile, &config); err != nil {
panic(err)
}
}
func GetConfig() Config {
return config
}