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 } }
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 }
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 }
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 }
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) } }
// 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 }
// 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 } }
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 }
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() }
func (c *Config) Load() error { if _, err := toml.DecodeFile(c.path, &c.Data); err != nil { return err } return nil }
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 } }
func (m *Magnacarto) Load(fileName string) error { _, err := toml.DecodeFile(fileName, &m) if err != nil { return err } return nil }
// 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 }
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 } } } }
// 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 }
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 }
// 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 }
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 }
func InitConfig() error { _, err = toml.DecodeFile("./config.toml", &C) if err != nil { return fmt.Errorf("Failed to decode config: %s", err.Error()) } return nil }
func main() { var conf config.Config if _, err := toml.DecodeFile("configs.toml", &conf); err != nil { log.Fatal(err) } fmt.Println(conf) // pqStr := "user="******" 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) }
func main() { loggers.IsDebug = os.Getenv("GBW_DEBUG") == "1" fmt.Println(gocolorize.NewColor("magenta").Paint("gobuildweb > Build a Golang web application.\n")) cmds := map[string]Command{ "run": commandRun, "dist": commandDist, } flag.Parse() args := flag.Args() if len(args) == 0 { usage() } if cmd, ok := cmds[args[0]]; !ok { usage() } else { if fi, err := os.Stat("project.toml"); os.IsNotExist(err) { loggers.ERROR.Fatalf("Please provide a project.toml for web project.") } else if err != nil { loggers.ERROR.Fatalf("Accessing project.toml file error, %v.", err) } else if fi.IsDir() { loggers.ERROR.Fatalf("project.toml cannot be a directory.") } if _, err := toml.DecodeFile("project.toml", &rootConfig); err != nil { loggers.ERROR.Fatalf("Cannot decode the project.toml into TOML format, %v", err) } loggers.SUCC.Printf("Loaded project.toml... %s", rootConfig.Package.Name) if err := cmd(args[1:]); err != nil { loggers.ERROR.Fatalf("Executing command [%v] error, %v", args[0], err) } } }
func LoadConfigure() *Configure { dir := "conf" absDir := "." if _, err := os.Stat("../" + dir + "/"); err == nil { absDir, _ = filepath.Abs("../" + dir + "/") } else if _, err := os.Stat("../../" + dir + "/"); err == nil { absDir, _ = filepath.Abs("../../" + dir + "/") } else { absDir = binDir() + "/../" + dir } var file = absDir + "/../conf/server.cfg" var default_file = absDir + "/../conf/server_default.cfg" if _, err := os.Stat(file); err != nil { file = default_file } var config = Configure{} if _, err := toml.DecodeFile(file, &config); err != nil { panic(err) } fmt.Print(config) return &config }
func ParseConf(file string) bool { if x, e := toml.DecodeFile(file, &RC); e != nil { fmt.Println("Parse toml configuration file "+file+" error : ", e.Error()) os.Exit(1) } else if len(x.Undecoded()) > 0 { for _, xx := range x.Undecoded() { fmt.Print(xx, " ") } fmt.Println(" Decode failed. Please review your configuration file: ", file) os.Exit(1) } fmt.Println("Runtime Configurations:") fmt.Println("\tBindTo: ", RC.Bind) fmt.Println("\tEnabled domains: ", RC.Domains) fmt.Println("\tMySQL enabled: ", RC.MySQLEnabled) fmt.Println("\tIPDB Path: ", RC.IPDB) fmt.Println("\tServerLog: ", RC.ServerLog) fmt.Println("\tQueryLog: ", RC.QueryLog) fmt.Println("\tServerLogFormat: ", RC.ServerLogFormat) fmt.Println("\tQueryLogFormat: ", RC.QueryLogFormat) fmt.Println("\tLoglevel: ", RC.LogLevel) if RC.MySQLEnabled { fmt.Println("MySQL Conf: ") fmt.Println("\tMySQL Host: ", RC.MySQLConf.MySQLHost) fmt.Println("\tMySQL Port: ", RC.MySQLConf.MySQLPort) fmt.Println("\tMySQL DB: ", RC.MySQLConf.MySQLDB) fmt.Println("\tMySQL User: "******"\tMySQL Pass: "******"\tDomains in MySQL: ", RC.MySQLConf.DomainsInMySQL) fmt.Println("\t\t") } else { fmt.Println("Notice: MySQL backend is disabled") } return true }
func LoadConfig(f string) (tomlConfig, error) { filename, _ := filepath.Abs(f) var err error var config tomlConfig if _, err = toml.DecodeFile(filename, &config); err != nil { log.ERROR.Fatal(err) return config, err } log.INFO.Printf("Vendor: %s\n", config.VendorString) log.INFO.Printf("Source Type: %s\n", config.Source.Type) log.INFO.Printf("Source Image: %s\n", config.Source.Image) for artifactName, artifact := range config.Artifacts { log.INFO.Printf("Artifact: %s \n", artifactName) for recipeName, recipe := range artifact.Recipe { log.INFO.Printf("-> Recipe %s <-\n", recipeName) for eventsName, event := range recipe { log.INFO.Printf("-> Event %s : (%s.%s)\n", eventsName, event.Name, event.Action) } } } return config, err }
func getConfig(path string) (Config, error) { config := Config{} _, err := toml.DecodeFile(path, &config) if err != nil { return config, err } validationEmptyError := "`%s` value can't be empty" switch "" { case config.ListenAddress: return config, fmt.Errorf(validationEmptyError, "listen") case config.StashHost: return config, fmt.Errorf(validationEmptyError, "stash_host") case config.StashUser: return config, fmt.Errorf(validationEmptyError, "stash_user") case config.StashPassword: return config, fmt.Errorf(validationEmptyError, "stash_password") } return config, nil }
func loadConfigFile(file string) (*Config, error) { config := &Config{} if _, err := toml.DecodeFile(file, config); err != nil { return config, err } if config.Include != "" { if err := includeConfigFile(config, config.Include); err != nil { return config, err } } // for backward compatibility // merges sensu configs to plugin configs if _, ok := config.DeprecatedSensu["checks"]; ok { configLogger.Warningf("'sensu.checks.*' config format is DEPRECATED. Please use 'plugin.metrics.*' format.") if config.Plugin == nil { config.Plugin = map[string]PluginConfigs{} } if _, ok := config.Plugin["metrics"]; !ok { config.Plugin["metrics"] = PluginConfigs{} } for k, v := range config.DeprecatedSensu["checks"] { config.Plugin["metrics"]["DEPRECATED-sensu-"+k] = v } } return config, nil }
func loadConfig(file string) error { _, err := toml.DecodeFile(file, &configs) if err != nil { return err } return nil }
// ParseConfig parses the libnetwork configuration file func ParseConfig(tomlCfgFile string) (*Config, error) { var cfg Config if _, err := toml.DecodeFile(tomlCfgFile, &cfg); err != nil { return nil, err } return &cfg, nil }
func LoadConfig(configPath string, config *Config) (*Config, error) { _, err := toml.DecodeFile(configPath, config) if err != nil { return config, err } return config, nil }
// DecodeFile takes a file path for a toml config file // and returns a pointer to a Config Struct. func DecodeFile(s string) (*Config, error) { t := &Config{} // Decode the toml file if _, err := toml.DecodeFile(s, t); err != nil { return nil, err } // Initialize Config struct // NOTE: Not happy with the implementation // but it will do for now for j, srs := range t.Series { for i := 0; i < srs.TagCount; i++ { tag := tag{ Key: fmt.Sprintf("tag-key-%d", i), Value: "tag-value", } srs.Tags = append(srs.Tags, tag) fmt.Println(srs) } t.Series[j] = srs } return t, nil }