当前位置: 首页>>代码示例>>Golang>>正文


Golang goconfig.LoadConfigFile函数代码示例

本文整理汇总了Golang中github.com/Unknwon/goconfig.LoadConfigFile函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadConfigFile函数的具体用法?Golang LoadConfigFile怎么用?Golang LoadConfigFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LoadConfigFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: LoadConfig

// Loads the config file
func LoadConfig() {
	// Read some flags if set
	//
	// FIXME read these from the config file too
	Config.Verbose = *verbose
	Config.Quiet = *quiet
	Config.ModifyWindow = *modifyWindow
	Config.Checkers = *checkers
	Config.Transfers = *transfers
	Config.DryRun = *dryRun
	Config.Timeout = *timeout
	Config.ConnectTimeout = *connectTimeout
	Config.CheckSum = *checkSum
	Config.SizeOnly = *sizeOnly
	Config.DumpHeaders = *dumpHeaders
	Config.DumpBodies = *dumpBodies

	ConfigPath = *configFile

	// Load configuration file.
	var err error
	ConfigFile, err = goconfig.LoadConfigFile(ConfigPath)
	if err != nil {
		log.Printf("Failed to load config file %v - using defaults: %v", ConfigPath, err)
		ConfigFile, err = goconfig.LoadConfigFile(os.DevNull)
		if err != nil {
			log.Fatalf("Failed to read null config file: %v", err)
		}
	}

	// Start the token bucket limiter
	startTokenBucket()
}
开发者ID:Blackfin,项目名称:rclone,代码行数:34,代码来源:config.go

示例2: SetConfig

func SetConfig() {
	var err error
	Cfg, err = cfg.LoadConfigFile("config.ini")
	if err != nil {
		Cfg, err = cfg.LoadConfigFile("../config.ini")
	}
}
开发者ID:mchobits,项目名称:go-blog,代码行数:7,代码来源:conf.go

示例3: LoadConfig

// LoadConfig loads the config file
func LoadConfig() {
	// Read some flags if set
	//
	// FIXME read these from the config file too
	Config.Verbose = *verbose
	Config.Quiet = *quiet
	Config.ModifyWindow = *modifyWindow
	Config.Checkers = *checkers
	Config.Transfers = *transfers
	Config.DryRun = *dryRun
	Config.Timeout = *timeout
	Config.ConnectTimeout = *connectTimeout
	Config.CheckSum = *checkSum
	Config.SizeOnly = *sizeOnly
	Config.IgnoreExisting = *ignoreExisting
	Config.DumpHeaders = *dumpHeaders
	Config.DumpBodies = *dumpBodies
	Config.InsecureSkipVerify = *skipVerify

	ConfigPath = *configFile

	Config.DeleteBefore = *deleteBefore
	Config.DeleteDuring = *deleteDuring
	Config.DeleteAfter = *deleteAfter

	switch {
	case *deleteBefore && (*deleteDuring || *deleteAfter),
		*deleteDuring && *deleteAfter:
		log.Fatalf(`Only one of --delete-before, --delete-during or --delete-after can be used.`)

	// If none are specified, use "during".
	case !*deleteBefore && !*deleteDuring && !*deleteAfter:
		Config.DeleteDuring = true
	}

	// Load configuration file.
	var err error
	ConfigFile, err = goconfig.LoadConfigFile(ConfigPath)
	if err != nil {
		log.Printf("Failed to load config file %v - using defaults: %v", ConfigPath, err)
		ConfigFile, err = goconfig.LoadConfigFile(os.DevNull)
		if err != nil {
			log.Fatalf("Failed to read null config file: %v", err)
		}
	}

	// Load filters
	Config.Filter, err = NewFilter()
	if err != nil {
		log.Fatalf("Failed to load filters: %v", err)
	}

	// Start the token bucket limiter
	startTokenBucket()
}
开发者ID:stengaard,项目名称:rclone,代码行数:56,代码来源:config.go

示例4: initConfig

func initConfig() {
	var err error
	cfg, err = goconfig.LoadConfigFile(config_file)
	if err != nil {
		log.Fatalf("CANNOT load config file(%s) : %s\n", config_file, err)
	}
	cfg_tunnel, err = goconfig.LoadConfigFile(config_tunnel_file)
	if err != nil {
		log.Fatalf("CANNOT load config file(%s) : %s\n", config_file, err)
	}
}
开发者ID:mehulsbhatt,项目名称:TunnelMonitor,代码行数:11,代码来源:config.go

示例5: init

func init() {
	if !isExist(_CFG_PATH) {
		os.Create(_CFG_PATH)
	}

	var err error
	Cfg, err = goconfig.LoadConfigFile(_CFG_PATH)
	if err == nil {
		beego.Info("Initialize app.ini")
	}

	setGithubCredentials(Cfg.MustValue("github", "client_id"),
		Cfg.MustValue("github", "client_secret"))

	docLock = new(sync.RWMutex)

	// Load documentation.
	initDocMap()

	// Start check ticker.
	checkTicker = time.NewTicker(5 * time.Minute)
	go checkTickerTimer(checkTicker.C)

	checkDocUpdates()
}
开发者ID:jingz8804,项目名称:beeweb,代码行数:25,代码来源:models.go

示例6: LoadBangoConfig

func LoadBangoConfig(fileName string) {
	var err error
	_, err = os.Stat(fileName)

	if err != nil {
		if os.IsNotExist(err) {
			panic("Configuration file does not exists: " + err.Error())
		} else {
			panic("Something wrong with configuration file: " + err.Error())
		}
	}

	var cfg *goconfig.ConfigFile
	cfg, err = goconfig.LoadConfigFile(fileName)
	if err != nil {
		panic("Fail to load configuration file: " + err.Error())
	}
	// Parse the global section
	config.global.debug = cfg.MustBool("global", "debug", false)

	// Parse the redis section
	config.redis.server = cfg.MustValue("redis", "server", "localhost")
	config.redis.port = cfg.MustValue("redis", "port", "6379")
	config.redis.db = cfg.MustInt("redis", "db", 0)
	config.redis.pass = cfg.MustValue("redis", "pass", "")

	// Parse the fail2ban section
	config.fail2ban.channel = cfg.MustValue("fail2ban", "channel", "fail2ban")
	config.fail2ban.jail = cfg.MustValue("fail2ban", "jail", "fail2ban-recidive")
	config.fail2ban.useF2C = cfg.MustBool("fail2ban", "usef2bclient", true)
}
开发者ID:uu,项目名称:bango,代码行数:31,代码来源:bango.go

示例7: InitModels

func InitModels() {
	if !com.IsFile(_CFG_PATH) {
		os.Create(_CFG_PATH)
	}

	var err error
	Cfg, err = goconfig.LoadConfigFile(_CFG_PATH)
	if err == nil {
		beego.Info("Initialize app.ini")
	}

	setGithubCredentials(Cfg.MustValue("github", "client_id"),
		Cfg.MustValue("github", "client_secret"))

	docLock = new(sync.RWMutex)
	blogLock = new(sync.RWMutex)

	initMaps()

	// Start check ticker.
	checkTicker = time.NewTicker(5 * time.Minute)
	go checkTickerTimer(checkTicker.C)

	// ATTENTION: you'd better comment following code when developing.
	if needCheckUpdate() {
		checkFileUpdates()

		Cfg.SetValue("app", "update_check_time", strconv.Itoa(int(time.Now().Unix())))
		goconfig.SaveConfigFile(Cfg, _CFG_PATH)
	}
}
开发者ID:rails0330,项目名称:beeweb,代码行数:31,代码来源:models.go

示例8: CoverConfigByUser

//覆盖配置
func CoverConfigByUser() {
	confPath := "conf/conf.ini"
	coverConfs, err := goconfig.LoadConfigFile(confPath)
	if err != nil {
		Waring("Can't find config file:conf/conf.ini ! Use default config.", err.Error())
		return
	}

	if appname, err := coverConfs.GetValue(goconfig.DEFAULT_SECTION, "AppName"); err == nil {
		AppName = appname
	}

	if httpAddress, err := coverConfs.GetValue(goconfig.DEFAULT_SECTION, "HttpAddress"); err == nil {
		HttpAddress = httpAddress
	}

	if httpPort, err := coverConfs.Int(goconfig.DEFAULT_SECTION, "HttpPort"); err == nil {
		HttpPort = httpPort
	}

	if httpServerTimeOut, err := coverConfs.Int64(goconfig.DEFAULT_SECTION, "HttpServerTimeOut"); err == nil {
		HttpServerTimeOut = httpServerTimeOut
	}

	if sessionOn, err := coverConfs.Bool(goconfig.DEFAULT_SECTION, "SessionOn"); err == nil {
		SessionOn = sessionOn
	}
}
开发者ID:basakakoel,项目名称:slimgo,代码行数:29,代码来源:config.go

示例9: TestConfig

func TestConfig(t *testing.T) {
	config, err := goconfig.LoadConfigFile("chat_conf.ini")
	if err != nil {
		t.Error(err)
	}

	host, err := config.GetValue("redis", "host")
	if err != nil {
		t.Error(err)
	}

	port, err := config.GetValue("redis", "port")
	if err != nil {
		t.Error(err)
	}

	fmt.Println("redis config, host:", host, " port:", port)

	portNum, err := strconv.Atoi(port)
	if err != nil {
		t.Error(err)
	}

	cfg := &redisConfig{host: host, port: portNum}
	fmt.Println("create config obj:", cfg)
	fmt.Println("redis config, host:", cfg.host, " port:", cfg.port)
}
开发者ID:alice-jiao,项目名称:Practice,代码行数:27,代码来源:clichat_test.go

示例10: init

func init() {
	hd, err := com.HomeDir()
	if err != nil {
		log.Error("", "Fail to get current user")
		log.Fatal("", err.Error())
	}

	HomeDir = strings.Replace(RawHomeDir, "~", hd, -1)

	cfgPath := path.Join(HomeDir, GOPM_CONFIG_FILE)
	if !com.IsExist(cfgPath) {
		os.MkdirAll(path.Dir(cfgPath), os.ModePerm)
		if _, err = os.Create(cfgPath); err != nil {
			log.Error("", "Fail to create gopm config file")
			log.Fatal("", err.Error())
		}
	}
	Cfg, err = goconfig.LoadConfigFile(cfgPath)
	if err != nil {
		log.Error("", "Fail to load gopm config file")
		log.Fatal("", err.Error())
	}

	LoadLocalNodes()
	LoadPkgNameList(path.Join(HomeDir, PKG_NAME_LIST_PATH))
}
开发者ID:kulasama,项目名称:gopm,代码行数:26,代码来源:conf.go

示例11: init

func init() {

	c, err := goconfig.LoadConfigFile("conf/conf.ini")
	if err != nil {
		panic(err)
	}

	driver, err := c.GetValue("Database", "driver")
	if err != nil {
		panic(err)
	}
	dsn, err := c.GetValue("Database", "dsn")

	if err != nil {
		panic(err)
	}

	DataBase, err = xorm.NewEngine(driver, dsn)
	if err != nil {
		panic(err)
	}

	err = DataBase.Ping()
	if err != nil {
		panic(err)
	}
}
开发者ID:kyugao,项目名称:gametcp_ex,代码行数:27,代码来源:sql.go

示例12: LoadConfig

func LoadConfig() (*goconfig.ConfigFile, error) {
	cfg, err := goconfig.LoadConfigFile("gowest.ini")
	if err != nil {
		return nil, err
	}
	return cfg, nil
}
开发者ID:rvowles,项目名称:gowest,代码行数:7,代码来源:gowest.go

示例13: LoadConfig

// LoadConfig loads configuration file.
func LoadConfig(cfgPath string) (*goconfig.ConfigFile, error) {
	if !com.IsExist(cfgPath) {
		os.Create(cfgPath)
	}

	return goconfig.LoadConfigFile(cfgPath)
}
开发者ID:sirithink,项目名称:beebbs,代码行数:8,代码来源:conf.go

示例14: FetchFromEnv

func (cred *Credentials) FetchFromEnv(path string) {

	// Load config
	cfg, err := goconfig.LoadConfigFile(path)

	// Parse
	clientId, err := cfg.GetValue(goconfig.DEFAULT_SECTION, "id")
	clientSecret, err := cfg.GetValue(goconfig.DEFAULT_SECTION, "secret")

	// Check for errors
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	// Check for empty values
	if len(clientId) == 0 || len(clientSecret) == 0 {
		log.Fatal("[tesla]: No config found .. ")
		os.Exit(1)
	}

	// Set on Credentials
	cred.ClientId = clientId
	cred.ClientSecret = clientSecret

	// trace
	Ok("[OK] Oauth credentials found")

}
开发者ID:amaniak,项目名称:tesla,代码行数:29,代码来源:credentials.go

示例15: LoadConfig

// LoadConfig loads configuration file.
func LoadConfig(cfgPath string) {
	if !com.IsExist(cfgPath) {
		os.Create(cfgPath)
	}

	var err error
	Cfg, err = goconfig.LoadConfigFile(cfgPath)
	if err != nil {
		log.Fatalf("Fail to load configuration file: %v", err)
	}
	if com.IsFile("custom/app.ini") {
		if err = Cfg.AppendFiles("custom/app.ini"); err != nil {
			log.Fatalf("Fail to load custom configuration file: %v", err)
		}
	}

	DocsJsPath, err = Cfg.GetValue("server", "docs_js_path")
	if err != nil {
		log.Fatalln("Fail to load configuration file: cannot find key docs_js_path")
	}

	HvJsPath, err = Cfg.GetValue("server", "hv_js_path")
	if err != nil {
		log.Fatalln("Fail to load configuration file: cannot find key hv_js_path")
	}
}
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:27,代码来源:utils.go


注:本文中的github.com/Unknwon/goconfig.LoadConfigFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。