123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package service
- import (
- "os"
- "github.com/BurntSushi/toml"
- )
- type Config struct {
- WebAddr string `toml:"WebAddr"`
- WebIndex string `toml: "WebIndex"`
- REFRESH_TOKENS string `toml: "REFRESH_TOKENS"`
- PUSHPLUS_TOKEN string `toml: "PUSHPLUS_TOKEN"`
- EmailUser string `toml: "EmailUser"`
- EmailPwd string `toml: "EmailPwd"`
- EmailSmtp string `toml: "EmailSmtp"`
- EmailTls bool `toml: "EmailTls"`
- Username string `toml:"Username"`
- Password string `toml:"Password"`
- }
- var config *Config
- func LoadConfig(path string) *Config {
- conf := &Config{}
- _, err := toml.DecodeFile(path, conf)
- if err != nil {
- panic(err)
- }
- config = conf
- logger.Info(config)
- return config
- }
- // todo
- func saveConfig() {
- // sava config to file
- conf := &Config{}
- conf.WebAddr = config.WebAddr
- conf.WebIndex = config.WebIndex
- conf.REFRESH_TOKENS = config.REFRESH_TOKENS
- conf.PUSHPLUS_TOKEN = config.PUSHPLUS_TOKEN
- conf.EmailUser = config.EmailUser
- conf.EmailPwd = config.EmailPwd
- conf.EmailSmtp = config.EmailSmtp
- conf.EmailTls = config.EmailTls
- conf.Username = config.Username
- conf.Password = config.Password
- // save to file config.toml
- file, err := os.Create("config.toml")
- if err != nil {
- panic(err)
- }
- defer file.Close()
-
- encoder := toml.NewEncoder(file)
- err = encoder.Encode(conf)
- if err != nil {
- panic(err)
- }
- logger.Info("config saved to file config.toml")
- }
|