Example #1
0
func init() {
	binDir, err := process.ExecutableDir()
	if err != nil {
		panic(err)
	}
	ROOT = path.Dir(binDir)

	// Load配置文件
	configFile := ROOT + "/conf/config.json"
	content, err := ioutil.ReadFile(configFile)
	if err != nil {
		panic(err)
	}
	Config = make(map[string]string)
	err = json.Unmarshal(content, &Config)
	if err != nil {
		panic(err)
	}
}
Example #2
0
func load_config(file string) (config map[string]string, err error) {
	binDir, err := process.ExecutableDir()
	if err != nil {
		return nil, (err)
	}
	ROOT = path.Dir(binDir)

	// Load 全局配置文件
	configFile := ROOT + file
	content, err := ioutil.ReadFile(configFile)
	if err != nil {
		return nil, (err)
	}
	config = make(map[string]string)
	err = json.Unmarshal(content, &config)
	if err != nil {
		return nil, (err)
	}

	return config, nil
}
Example #3
0
func save_config(file string, config map[string]string) (err error) {
	binDir, err := process.ExecutableDir()
	if err != nil {
		return (err)
	}
	ROOT = path.Dir(binDir)

	var content []byte

	//
	content, err = json.Marshal(&config)
	if err != nil {
		return (err)
	}

	configFile := ROOT + file
	err = ioutil.WriteFile(configFile, content, 666)
	if err != nil {
		return (err)
	}

	return nil
}
Example #4
0
func init() {
	binDir, err := process.ExecutableDir()
	if err != nil {
		panic(err)
	}
	ROOT = path.Dir(binDir) + "/"

	if !strings.Contains(ROOT, "studygolang") {
		ROOT, _ = os.Getwd()
		ROOT = ROOT[:strings.Index(ROOT, "src")]
	}

	// Load配置文件
	configFile := ROOT + "conf/config.json"
	content, err := ioutil.ReadFile(configFile)
	if err != nil {
		panic(err)
	}
	Config = make(map[string]string)
	err = json.Unmarshal(content, &Config)
	if err != nil {
		panic(err)
	}
}