• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang goconfig.LoadConfigFile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: NewConfigContext

func NewConfigContext() {
	workDir, err := ExecDir()
	if err != nil {
		qlog.Fatalf("Fail to get work directory: %s\n", err)
	}

	cfgPath := filepath.Join(workDir, "conf/app.ini")
	Cfg, err = goconfig.LoadConfigFile(cfgPath)
	if err != nil {
		qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
	}
	Cfg.BlockMode = false

	cfgPaths := []string{os.Getenv("GOGS_CONFIG"), filepath.Join(workDir, "custom/conf/app.ini")}
	for _, cfgPath := range cfgPaths {
		if com.IsFile(cfgPath) {
			if err = Cfg.AppendFiles(cfgPath); err != nil {
				qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
			}
		}
	}

	AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
	AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
	AppUrl = Cfg.MustValue("server", "ROOT_URL")
	Domain = Cfg.MustValue("server", "DOMAIN")
	OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
	DisableRouterLog = Cfg.MustBool("server", "DISABLE_ROUTER_LOG", false)
	SecretKey = Cfg.MustValue("security", "SECRET_KEY")

	InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)

	RunUser = Cfg.MustValue("", "RUN_USER")
	curUser := os.Getenv("USER")
	if len(curUser) == 0 {
		curUser = os.Getenv("USERNAME")
	}
	// Does not check run user when the install lock is off.
	if InstallLock && RunUser != curUser {
		qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
	}

	LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
	CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME")
	CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")

	PictureService = Cfg.MustValue("picture", "SERVICE")
	DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR", false)

	// Determine and create root git reposiroty path.
	homeDir, err := com.HomeDir()
	if err != nil {
		qlog.Fatalf("Fail to get home directory): %v\n", err)
	}
	RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
	if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
		qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
	}
	ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash")
}
开发者ID:CubeLite,项目名称:gogs,代码行数:60,代码来源:conf.go


示例17: init

func init() {
	conf, _ := goconfig.LoadConfigFile("./conf/db.ini")
	conf_sq := "local"
	slimmysql.RegisterConnectionDefault(conf.MustBool(conf_sq, "rwseparate"), conf.MustValue(conf_sq, "host"), conf.MustValue(conf_sq, "port"), conf.MustValue(conf_sq, "db"), conf.MustValue(conf_sq, "user"), conf.MustValue(conf_sq, "pass"), conf.MustValue(conf_sq, "prefix"), false)
	conf_sq = "company"
	slimmysql.RegisterConnection("biteabc", conf.MustBool(conf_sq, "rwseparate"), conf.MustValue(conf_sq, "host"), conf.MustValue(conf_sq, "port"), conf.MustValue(conf_sq, "db"), conf.MustValue(conf_sq, "user"), conf.MustValue(conf_sq, "pass"), conf.MustValue(conf_sq, "prefix"), false)
}
开发者ID:hythht,项目名称:slimgotest,代码行数:7,代码来源:model.go


示例18: init

func init() {
	if cfg, err := goconfig.LoadConfigFile("config.ini"); err == nil {
		dbUser, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbuser")
		dbPassword, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbpass")
		dbHost, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbhost")
		dbPort, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbport")
		dbName, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbname")
	} else {
		log.Println("读取配置文件conf.ini失败")
	}

	orm.DefaultTimeLoc = time.Local
	maxIdle := 50  //(可选)  设置最大空闲连接
	maxConn := 100 //(可选)  设置最大数据库连接 (go >= 1.2)
	connStr := fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8",
		dbUser,
		dbPassword,
		dbHost,
		dbPort,
		dbName,
	) + "&loc=" + url.QueryEscape("Local")

	if err := orm.RegisterDataBase("default", "mysql",
		connStr,
		maxIdle,
		maxConn,
	); err != nil {
		log.Println(err.Error())
	}

}
开发者ID:endville,项目名称:gpsgate,代码行数:31,代码来源:db.go


示例19: beforeRun

func (this *App) beforeRun() {
	//Session
	if SessionOn {
		confPath := "conf/conf.ini"
		sessConfs, err := goconfig.LoadConfigFile(confPath)
		if err != nil {
			Waring("Can't find config file:conf/conf.ini ! ", err.Error())
			return
		}
		section := "session"
		sessionProvider := sessConfs.MustValue(section, "Provider")
		path := sessConfs.MustValue(section, "Path")
		cookieKey := sessConfs.MustValue(section, "CookieKey")
		domain := sessConfs.MustValue(section, "Domain")
		gcLifeTime := sessConfs.MustInt(section, "GcLifeTime")
		maxLifeTime := sessConfs.MustInt(section, "MaxLifeTime")
		cookieLifeTime := sessConfs.MustInt(section, "CookieLifeTime")
		seesionIdLength := sessConfs.MustInt(section, "SessionIdLength")
		SessionFactory, err = session.NewSessionFactory(sessionProvider, cookieKey, domain, path, gcLifeTime, maxLifeTime, cookieLifeTime, seesionIdLength)
		if err != nil {
			panic("Init session failed." + err.Error())
		}

		// RegisterHookBeforeHttpPre("session", func(ctx *context.Context) {
		// 	var err error
		// 	ctx.Input.Session, err = SessionFactory.SessionStart(ctx.Request, ctx.ResponseWriter)
		// 	if err != nil {
		// 		Error("Session start failed.", err.Error())
		// 	}
		// })

		// RegisterHookAfterHttpFinish("session_save", func(ctx *context.Context) {
		// 	ctx.Input.Session.SessionSave(ctx.ResponseWriter)
		// })
	}

	//view
	err := BuildTpl(ViewPath)
	if err != nil {
		Error("Build template failed,", err.Error())
	}

	//timetask
	for name, t := range tasks {
		if t.runtag == true {
			go t.Start()
			Logger.Info("Timetask:", name, " is running.")
		}
	}

	//hooks
	for key, f := range hooks.hookBeforeAppRun {
		err := f()
		if err != nil {
			Logger.Error("Hook:", key, " err,", err.Error())
		} else {
			Logger.Info("Hook:", key, " finished.")
		}
	}
}
开发者ID:jesusslim,项目名称:slimgo,代码行数:60,代码来源:app.go


示例20: CreateIniFile

func CreateIniFile() error {
	f, err := os.OpenFile("./server.ini", os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		return err
	}

	defer f.Close()

	config, err = goconfig.LoadConfigFile("./server.ini")
	if err != nil {
		return err
	}

	config.SetSectionComments("App", "")
	config.SetSectionComments("User", "")

	config.SetValue("App", "IP", "127.0.0.1")
	config.SetValue("App", "Port", "8080")
	config.SetValue("User", "username", "admin")
	config.SetValue("User", "password", helper.MD5("admin"))

	err = goconfig.SaveConfigFile(config, "./server.ini")
	if err != nil {
		return err
	}

	return nil
}
开发者ID:sevenzoe,项目名称:FiveMusketeers,代码行数:28,代码来源:config.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang goconfig.SaveConfigFile函数代码示例发布时间:2022-05-28
下一篇:
Golang com.ToStr函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap