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


Golang ConfigFile.MustValue方法代码示例

本文整理汇总了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)
}
开发者ID:uu,项目名称:bango,代码行数:31,代码来源:bango.go

示例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!")
}
开发者ID:kulasama,项目名称:gopm,代码行数:66,代码来源:run.go


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