✨ Initial work on parsing config file
This commit is contained in:
parent
4139d835be
commit
996f59c8af
4 changed files with 51 additions and 4 deletions
39
config/config.go
Normal file
39
config/config.go
Normal 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
|
||||
}
|
||||
Reference in a new issue