本文整理匯總了Golang中github.com/Unknwon/goconfig.ConfigFile.MustValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang ConfigFile.MustValue方法的具體用法?Golang ConfigFile.MustValue怎麽用?Golang ConfigFile.MustValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Unknwon/goconfig.ConfigFile
的用法示例。
在下文中一共展示了ConfigFile.MustValue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: runRun
func runRun(ctx *cli.Context) {
setup(ctx)
//support unix only
if ctx.Bool("local") {
var localPath string
var err error
var wd string
var gf *goconfig.ConfigFile
wd, _ = os.Getwd()
for wd != "/" {
gf, _ = goconfig.LoadConfigFile(".gopmfile")
if gf != nil {
localPath = gf.MustValue("project", "localPath")
}
if localPath != "" {
break
}
os.Chdir("..")
wd, _ = os.Getwd()
}
if wd == "/" {
log.Fatal("run", "no gopmfile in the directory or parent directory")
}
argss := gf.MustValue("run", "cmd")
if localPath == "" {
log.Fatal("run", "No localPath set")
}
args := strings.Split(argss, " ")
argsLen := len(args)
for i := 0; i < argsLen; i++ {
strings.Trim(args[i], " ")
}
if len(args) < 2 {
log.Fatal("run", "cmd arguments less than 2")
}
err = execCmd(localPath, localPath, args...)
if err != nil {
log.Error("run", "Fail to run program:")
log.Fatal("", "\t"+err.Error())
}
return
}
// Get GOPATH.
installGopath = com.GetGOPATHs()[0]
if com.IsDir(installGopath) {
isHasGopath = true
log.Log("Indicated GOPATH: %s", installGopath)
installGopath += "/src"
}
// run command with gopm repos context
// need version control , auto link to GOPATH/src repos
genNewGoPath(ctx, false)
defer os.RemoveAll(doc.VENDOR)
log.Trace("Running...")
cmdArgs := []string{"go", "run"}
cmdArgs = append(cmdArgs, ctx.Args()...)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil {
log.Error("run", "Fail to run program:")
log.Fatal("", "\t"+err.Error())
}
log.Success("SUCC", "run", "Command executed successfully!")
}