本文整理汇总了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()
}
示例2: SetConfig
func SetConfig() {
var err error
Cfg, err = cfg.LoadConfigFile("config.ini")
if err != nil {
Cfg, err = cfg.LoadConfigFile("../config.ini")
}
}
示例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()
}
示例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)
}
}
示例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()
}
示例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)
}
示例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)
}
}
示例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
}
}
示例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)
}
示例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))
}
示例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)
}
}
示例12: LoadConfig
func LoadConfig() (*goconfig.ConfigFile, error) {
cfg, err := goconfig.LoadConfigFile("gowest.ini")
if err != nil {
return nil, err
}
return cfg, nil
}
示例13: LoadConfig
// LoadConfig loads configuration file.
func LoadConfig(cfgPath string) (*goconfig.ConfigFile, error) {
if !com.IsExist(cfgPath) {
os.Create(cfgPath)
}
return goconfig.LoadConfigFile(cfgPath)
}
示例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")
}
示例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")
}
}