本文整理汇总了Golang中github.com/BurntSushi/toml.DecodeFile函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeFile函数的具体用法?Golang DecodeFile怎么用?Golang DecodeFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecodeFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ReadConfigfileServe
func ReadConfigfileServe(path string, configCh chan BgpConfigSet, reloadCh chan bool) {
cnt := 0
for {
<-reloadCh
b := Bgp{}
p := RoutingPolicy{}
md, err := toml.DecodeFile(path, &b)
if err == nil {
err = SetDefaultConfigValues(md, &b)
if err == nil {
_, err = toml.DecodeFile(path, &p)
}
}
if err != nil {
if cnt == 0 {
log.Fatal("can't read config file ", path, ", ", err)
} else {
log.Warning("can't read config file ", path, ", ", err)
continue
}
}
if cnt == 0 {
log.Info("finished reading the config file")
}
cnt++
bgpConfig := BgpConfigSet{Bgp: b, Policy: p}
configCh <- bgpConfig
}
}
开发者ID:nikolayvoronchikhin,项目名称:netplugin,代码行数:31,代码来源:serve.go
示例2: LoadConfig
func LoadConfig(name, version, cfgname string) (config Config, err error) {
sysconf := path.Join(sysConfigDir(name, version), cfgname)
userconf := path.Join(userConfigDir(name, version), cfgname)
selfconf := path.Join(selfConfigDir(), cfgname)
cwdconf := path.Join(utils.CwdDir(), cfgname)
defer func() {
config.AppName = name
config.AppVersion = version
config.AppConfig = cfgname
}()
if utils.IsFile(cwdconf) {
if _, err = toml.DecodeFile(cwdconf, &config); err != nil {
return
}
} else if utils.IsFile(selfconf) {
if _, err = toml.DecodeFile(selfconf, &config); err != nil {
return
}
} else if utils.IsFile(userconf) {
if _, err = toml.DecodeFile(userconf, &config); err != nil {
return
}
} else if utils.IsFile(sysconf) {
if _, err = toml.DecodeFile(sysconf, &config); err != nil {
return
}
} else {
fmt.Printf("\n*** 无法找到配置文件,有效的配置文件路径列表为(按顺序查找)***\n\n1. %s\n2. %s\n3. %s\n", selfconf, userconf, sysconf)
}
return
}
开发者ID:yetist,项目名称:xmppbot,代码行数:31,代码来源:config.go
示例3: main
func main() {
// 初始化Log
stdOutput := logging.NewLogBackend(os.Stderr, "", 0)
stdOutputFormatter := logging.NewBackendFormatter(stdOutput, format)
logging.SetBackend(stdOutputFormatter)
redis = goredis.NewClient(redisConf)
// 读取参数来获得配置文件的名称
argCount := len(os.Args)
if argCount == 0 {
log.Warning("需要输入配置文件名称: 格式 '-c fileName'")
return
}
cmd := flag.String("c", "help", "配置文件名称")
flag.Parse()
if *cmd == "help" {
log.Warning("需要输入配置文件名称: 格式 '-c fileName'")
return
}
if _, err := toml.DecodeFile(*cmd, &config); err != nil {
log.Error("配置文件有问题: %v", err)
return
}
if _, err := toml.DecodeFile("comments.toml", &leaveComments); err != nil {
log.Error("解析留言列表有问题: %v", err)
return
}
_saveCommentsToRedis()
// for i := 0; i < 100000; i++ {
// log.Debug("Comment: %v", _getRandomComment())
// }
epicHelper := []PlayerInfo{}
for _, info := range config.PlayerInfo {
if info.EpicHelper == true {
epicHelper = append(epicHelper, info)
}
}
if len(epicHelper) == 0 {
log.Error("没有配置帮飞号信息")
return
}
ch := make(chan int, len(epicHelper))
for _, playerInfo := range epicHelper {
go MakeRequest(playerInfo, ch)
}
<-ch
}
开发者ID:BendustiK,项目名称:WalkrHelper,代码行数:58,代码来源:epic.go
示例4: load
func (t *testCase) load() error {
if _, err := toml.DecodeFile("config.tml", &t); err != nil {
return err
}
if _, err := toml.DecodeFile(filepath.Join("cases", t.Name, "config.tml"), &t); err != nil && !os.IsNotExist(err) {
return err
}
return nil
}
开发者ID:nebulon42,项目名称:magnacarto,代码行数:9,代码来源:regression_test.go
示例5: append_config_files
func append_config_files(ar int, outputDir string, IPVersion string, noQuagga bool, normalBGP bool) {
gobgpConf := config.Bgp{
Global: config.Global{
As: 65000,
RouterId: net.ParseIP("192.168.255.1"),
},
}
c := config.Neighbor{
PeerAs: 65000 + uint32(ar),
NeighborAddress: net.ParseIP(fmt.Sprintf("%s%d", baseNeighborAddress[IPVersion], ar)),
AuthPassword: fmt.Sprintf("hoge%d", ar),
RouteServer: config.RouteServer{RouteServerClient: !normalBGP},
TransportOptions: config.TransportOptions{PassiveMode: true},
Timers: config.Timers{HoldTime: 30, KeepaliveInterval: 10, IdleHoldTimeAfterReset: 10},
PeerType: config.PEER_TYPE_EXTERNAL,
}
if !noQuagga {
q := NewQuaggaConfig(ar, &gobgpConf.Global, &c, net.ParseIP(serverAddress[IPVersion]))
os.Mkdir(fmt.Sprintf("%s/q%d", outputDir, ar), 0755)
var err error
if IPVersion == IPv6 {
err = ioutil.WriteFile(fmt.Sprintf("%s/q%d/bgpd.conf", outputDir, ar), q.IPv6Config().Bytes(), 0644)
} else {
err = ioutil.WriteFile(fmt.Sprintf("%s/q%d/bgpd.conf", outputDir, ar), q.IPv4Config().Bytes(), 0644)
}
if err != nil {
log.Fatal(err)
}
}
newConf := config.Bgp{}
_, d_err := toml.DecodeFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), &newConf)
if d_err != nil {
log.Fatal(d_err)
}
newConf.NeighborList = append(newConf.NeighborList, c)
var buffer bytes.Buffer
encoder := toml.NewEncoder(&buffer)
encoder.Encode(newConf)
policyConf := &config.RoutingPolicy{}
_, p_err := toml.DecodeFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), policyConf)
if p_err != nil {
log.Fatal(p_err)
}
if policyConf != nil && len(policyConf.PolicyDefinitionList) != 0 {
encoder.Encode(policyConf)
}
e_err := ioutil.WriteFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), buffer.Bytes(), 0644)
if e_err != nil {
log.Fatal(e_err)
}
}
开发者ID:ttaanngg,项目名称:gobgp,代码行数:56,代码来源:quagga-rsconfig.go
示例6: overlayConfig
// TODO(edanaher): This config parsing is kind of horrendous, but hopefully does the right thing.
func overlayConfig() {
if clientOpts.Config != "" {
_, err := toml.DecodeFile(clientOpts.Config, cfg)
if err != nil {
fmt.Print("Error parsing config file " + clientOpts.Config + ":\n" + err.Error() + "\n")
os.Exit(1)
}
} else {
// NOTE(edanaher): The default doesn't get removed if more are passed in
if len(clientOpts.Regions) > 1 {
clientOpts.Regions = clientOpts.Regions[1:]
}
for _, region := range clientOpts.Regions {
configFileFound := false
for _, path := range configDirs {
filename := path + "client." + region + ".toml"
if ok, _ := exists(filename); ok {
var curCfg ClientConfig
_, err := toml.DecodeFile(filename, &curCfg)
if err != nil {
fmt.Print("Error parsing config file " + filename + ":\n" + err.Error() + "\n")
os.Exit(1)
}
// Defaults need to be loaded for each file independently
if curCfg.Port == 0 {
curCfg.Port = DefaultManagerRPCPort
}
if curCfg.KeyPath == "" {
curCfg.KeyPath = DefaultManagerKeyPath
}
cfg = append(cfg, &curCfg)
configFileFound = true
break
}
}
if !configFileFound {
fmt.Print("Error: could not find config file for " + region + "\n")
os.Exit(1)
}
}
}
// If other options are passed in, assume there's only one region and we should use that one
/* NOTE(edanaher): cfg has to be an array of interfaces, because arrays don't get auto-inferfaced properly.
* But then we have to cast it here. *sigh* */
if clientOpts.Host != "" {
cfg[0].(*ClientConfig).Host = clientOpts.Host
}
if clientOpts.Port != 0 {
cfg[0].(*ClientConfig).Port = clientOpts.Port
}
if clientOpts.KeyPath != "" {
cfg[0].(*ClientConfig).KeyPath = clientOpts.KeyPath
}
// TODO(edanaher): This is aliased. The appends above may have unaliased it. Why do we do this?
rpcClient.Opts = cfg
}
开发者ID:irregular,项目名称:atlantis-manager,代码行数:57,代码来源:client.go
示例7: Init
// Init initializes application settings.
func Init() {
var defaults s
if _, err := toml.DecodeFile("conf/app.toml", &defaults); err != nil {
panic(err)
}
var locals s
if _, err := toml.DecodeFile("conf/app_local.toml", &locals); err == nil {
mergo.Merge(&locals, defaults)
S = &locals
} else {
S = &defaults
}
}
开发者ID:Gr1N,项目名称:pacman,代码行数:15,代码来源:settings.go
示例8: Start
func (p *program) Start(s service.Service) error {
flagSet.Parse(os.Args[1:])
if *showVersion {
fmt.Println(util.Version("nsqlookupd"))
os.Exit(0)
return nil
}
var cfg map[string]interface{}
if *config != "" {
_, err := toml.DecodeFile(*config, &cfg)
if err != nil {
log.Fatalf("ERROR: failed to load config file %s - %s", *config, err.Error())
}
}
opts := nsqlookupd.NewNSQLookupdOptions()
options.Resolve(opts, flagSet, cfg)
p.daemon = nsqlookupd.NewNSQLookupd(opts)
p.daemon.Main()
return nil
}
开发者ID:judwhite,项目名称:nsq-0.3.2-win,代码行数:25,代码来源:nsqlookupd.go
示例9: main
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
// Load config
if _, err := toml.DecodeFile("acgsh.conf", &config); err != nil {
log.Fatalln("Error: can not load acgsh.conf", err)
return
}
adminTwisterUsername = config.TwisterUsername
//Init DB
db.Init()
defer db.Close()
//Init search engine
search.Init()
rpc.SetAddress(config.TwisterServer)
go runSyncTimeLine()
//btih, category, fileSize, title, ok := retrieveMagnetInfo("#acgsh maGnet:? dn = =& xt=urn:btih:A3TU7P63QSNXXSYN2PDQYDZV4IYRU2CG& x.C = 動畫 &xl=123124&dn=[诸神字幕组][高校星歌剧][High School Star Musical][12][繁日双语字幕][720P][CHT MP4]")
//println(btih, category, fileSize, title, ok)
startHttpServer()
}
开发者ID:acgshare,项目名称:acgsh,代码行数:27,代码来源:main.go
示例10: Load
func (c *Config) Load() error {
if _, err := toml.DecodeFile(c.path, &c.Data); err != nil {
return err
}
return nil
}
开发者ID:matthistuff,项目名称:simpleconf,代码行数:7,代码来源:simpleconf.go
示例11: init
func init() {
log.Println("configurations init called off")
dir, _ := os.Getwd()
// order in which to search for config file
files := []string{
dir + "/dev.ini",
dir + "/config.ini",
dir + "/conf/dev.ini",
dir + "/conf/config.ini",
}
for _, f := range files {
if _, err := toml.DecodeFile(f, &Setting); err == nil {
log.Printf("Loaded configuration %s", f)
break
}
}
if len(Setting.ServerPort) < 3 {
log.Panicln("Configuration files are not loaded properly, problem in finding port to run application.")
}
// make changes as per environment settings
if Setting.EnvMode == DEV {
// use dev mode database settings
Setting.DbSource = Setting.DbSourceDevMode
}
}
开发者ID:way-2-go,项目名称:go-boilerplate,代码行数:30,代码来源:conf.go
示例12: Load
func (m *Magnacarto) Load(fileName string) error {
_, err := toml.DecodeFile(fileName, &m)
if err != nil {
return err
}
return nil
}
开发者ID:kaiCu,项目名称:magnacarto,代码行数:7,代码来源:config.go
示例13: parseFlags
// parseFlags parses and validates the command line arguments.
func (cmd *Command) parseFlags(args []string) (*Config, string, error) {
fs := flag.NewFlagSet("", flag.ContinueOnError)
configPath := fs.String("config", "", "")
fs.SetOutput(cmd.Stderr)
fs.Usage = cmd.printUsage
if err := fs.Parse(args); err != nil {
return nil, "", err
}
// Parse configuration file from disk.
if *configPath == "" {
return nil, "", fmt.Errorf("config required")
}
// Parse config.
config := Config{
Meta: meta.NewConfig(),
Data: tsdb.NewConfig(),
}
if _, err := toml.DecodeFile(*configPath, &config); err != nil {
return nil, "", err
}
// Require output path.
path := fs.Arg(0)
if path == "" {
return nil, "", fmt.Errorf("snapshot path required")
}
return &config, path, nil
}
开发者ID:jportoles,项目名称:influxdb092,代码行数:32,代码来源:restore.go
示例14: loadLdapConfig
func loadLdapConfig() {
if !setting.LdapEnabled {
return
}
ldapLogger.Info("Ldap enabled, reading config file", "file", setting.LdapConfigFile)
_, err := toml.DecodeFile(setting.LdapConfigFile, &ldapCfg)
if err != nil {
ldapLogger.Crit("Failed to load ldap config file", "error", err)
os.Exit(1)
}
if len(ldapCfg.Servers) == 0 {
ldapLogger.Crit("ldap enabled but no ldap servers defined in config file")
os.Exit(1)
}
// set default org id
for _, server := range ldapCfg.Servers {
assertNotEmptyCfg(server.SearchFilter, "search_filter")
assertNotEmptyCfg(server.SearchBaseDNs, "search_base_dns")
for _, groupMap := range server.LdapGroups {
if groupMap.OrgId == 0 {
groupMap.OrgId = 1
}
}
}
}
开发者ID:Robin7Ma,项目名称:grafana,代码行数:30,代码来源:settings.go
示例15: parseToml
// parseToml parses a toml file and decodes it into the
// provided value, which must be passed as a pointer to
// some type that has already been allocated
func parseToml(fileName string, value interface{}) error {
_, err := toml.DecodeFile(fileName, value)
if err != nil {
log.Error(err.Error())
}
return err
}
开发者ID:basharal,项目名称:config,代码行数:10,代码来源:toml.go
示例16: LoadConfig
func LoadConfig(fp string) Config {
var tml TomlConfig
_, err := toml.DecodeFile(fp, &tml)
if err != nil {
log.Fatal("load toml: can't convert toml")
}
var slot []image.Point
for i := range tml.Slot {
slot = append(slot, itop(tml.Slot[i]))
}
var prgs []Progress
var prg Progress
for i := range tml.Progress {
prg = Progress{
Crop: itor(tml.Progress[i].Crop),
Paste: itop(tml.Progress[i].Paste),
}
prgs = append(prgs, prg)
}
// Configを初期化
conf := Config{
Type: tml.Type,
Image: tml.Image,
Crop: itor(tml.Crop),
Slot: slot,
Progress: prgs,
}
return conf
}
开发者ID:ayatk,项目名称:MinecraftRecipeMaker,代码行数:33,代码来源:template.go
示例17: NewTemplateResource
// NewTemplateResource creates a TemplateResource.
func NewTemplateResource(path string, config Config) (*TemplateResource, error) {
if config.StoreClient == nil {
return nil, errors.New("A valid StoreClient is required.")
}
var tc *TemplateResourceConfig
log.Debug("Loading template resource from " + path)
_, err := toml.DecodeFile(path, &tc)
if err != nil {
return nil, fmt.Errorf("Cannot process template resource %s - %s", path, err.Error())
}
tr := tc.TemplateResource
tr.expandEnv()
tr.keepStageFile = config.KeepStageFile
tr.noop = config.Noop
tr.storeClient = config.StoreClient
tr.funcMap = newFuncMap()
tr.store = memkv.New()
addFuncs(tr.funcMap, tr.store.FuncMap)
tr.prefix = filepath.Join("/", config.Prefix, tr.Prefix)
if tr.Src == "" {
return nil, ErrEmptySrc
}
tr.Src = filepath.Join(config.TemplateDir, tr.Src)
return &tr, nil
}
开发者ID:nebelpfade,项目名称:confd,代码行数:26,代码来源:resource.go
示例18: readConfig
func readConfig(path string, config *TomlConfig) error {
if _, err := toml.DecodeFile(path, config); err != nil {
glog.V(1).Infof("[DEBUG] read configure file fail:%v!", err.Error())
return err
}
return nil
}
开发者ID:renhuiyang,项目名称:go-shoppingweb-practise,代码行数:7,代码来源:main.go
示例19: InitConfig
func InitConfig() error {
_, err = toml.DecodeFile("./config.toml", &C)
if err != nil {
return fmt.Errorf("Failed to decode config: %s", err.Error())
}
return nil
}
开发者ID:okushchenko,项目名称:suplat,代码行数:7,代码来源:config.go
示例20: main
func main() {
var conf config.Config
if _, err := toml.DecodeFile("configs.toml", &conf); err != nil {
log.Fatal(err)
}
fmt.Println(conf)
// pqStr := "user=" + conf.DB.User + " password='" + conf.DB.Password + "' dbname=remindbot host=localhost sslmode=disable"
// fmt.Println(pqStr)
// db, err := sql.Open("postgres", pqStr)
// if err != nil {
// log.Fatal(err)
// }
// defer db.Close()
buf := bytes.NewBuffer(nil)
ac := handlers.NewAppContext(nil, conf, buf)
stack := alice.New()
r := router.New()
r.POST("/reminders", stack.ThenFunc(ac.CommandHandler))
fmt.Println("Server starting at port 8080.")
http.ListenAndServe(":8080", r)
}
开发者ID:aranair,项目名称:remindbot,代码行数:26,代码来源:main.go
注:本文中的github.com/BurntSushi/toml.DecodeFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论