本文整理汇总了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!")
}