當前位置: 首頁>>代碼示例>>Golang>>正文


Golang toml.DecodeFile函數代碼示例

本文整理匯總了Golang中github.com/BurntSushi/toml.DecodeFile函數的典型用法代碼示例。如果您正苦於以下問題:Golang DecodeFile函數的具體用法?Golang DecodeFile怎麽用?Golang DecodeFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了DecodeFile函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/BurntSushi/toml.DecodeFile函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。