配置读取#

使用https://github.com/BurntSushi/toml.git作为toml配置文件的解析库

我们只需要Config.LoadConfig()函数来读取配置文件,其他部分不需要关心。

func LoadConfig() error {
    // 这里的路径需要根据实际情况修改,指向你的配置文件
	if _, err := toml.DecodeFile("...../configs/config.toml", config); err != nil {
		log.Fatal(err.Error())
		return err
	}
	return nil
}

func GetConfig() *Config {
	if config == nil {
		config = new(Config)
		_ = LoadConfig()
	}
	return config
}
本站总访问量  ·  访客数
你的IP 获取中…