1 Star 0 Fork 34

loojk2008/distributed-gosuv

forked from dhm/distributed-gosuv 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
config.go 929 Bytes
一键复制 编辑 原始数据 按行查看 历史
haiker 提交于 2017-12-03 19:46 . 分布式实现
package main
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/go-yaml/yaml"
)
type Configuration struct {
Server struct {
HttpAuth struct {
Enabled bool `yaml:"enabled"`
User string `yaml:"username"`
Password string `yaml:"password"`
} `yaml:"httpauth"`
Addr string `yaml:"addr"`
Master string `yaml:"master"`
} `yaml:"server"`
Client struct {
ServerURL string `yaml:"server_url"`
}
}
func readConf(filename string) (c Configuration, err error) {
// initial default value
c.Server.Addr = ":11313" // in memory of 08-31 13:13
c.Client.ServerURL = "http://localhost:11313"
data, err := ioutil.ReadFile(filename)
if err != nil {
data = []byte("")
}
err = yaml.Unmarshal(data, &c)
if err != nil {
return
}
cfgDir := filepath.Dir(filename)
if !IsDir(cfgDir) {
os.MkdirAll(cfgDir, 0755)
}
data, _ = yaml.Marshal(c)
err = ioutil.WriteFile(filename, data, 0644)
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/loojk2004/distributed-gosuv.git
git@gitee.com:loojk2004/distributed-gosuv.git
loojk2004
distributed-gosuv
distributed-gosuv
master

搜索帮助