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

Golang goconfig.ConfigFile类代码示例

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

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



在下文中一共展示了ConfigFile类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: setField

func (i *INILoader) setField(field *structs.Field, c *goconfig.ConfigFile, section string) error {
	//first process each subfield of a struct field
	switch field.Kind() {
	case reflect.Struct:
		for _, f := range field.Fields() {
			var subsection string
			if section == "" {
				subsection = field.Name()
			} else {
				subsection = section + "." + field.Name()
			}
			if err := i.setField(f, c, subsection); err != nil {
				return err
			}
		}
	default:
		v, err := c.GetValue(section, field.Name())
		if err == nil && v != "" {
			err := fieldSet(field, v)
			if err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:heartsg,项目名称:dasea,代码行数:27,代码来源:file.go


示例2: GetLocal

func GetLocal(c *goconfig.ConfigFile) map[string]string {
	local := make(map[string]string)
	dir := c.GetKeyList("local")
	for _, v := range dir {
		row, _ := c.GetValue("local", v)
		local[strings.Trim(v, "#")] = row
	}
	return local
}
开发者ID:benlightning,项目名称:fabux,代码行数:9,代码来源:fabconfig.go


示例3: GetHost

func GetHost(c *goconfig.ConfigFile) map[string][]string {
	server := make(map[string][]string)
	host := c.GetKeyList("host")
	for _, v := range host {
		row, _ := c.GetValue("host", v)
		server[strings.Trim(v, "#")] = strings.Split(row, "`")
	}
	return server
}
开发者ID:benlightning,项目名称:fabux,代码行数:9,代码来源:fabconfig.go


示例4: GetGlobal

func GetGlobal(c *goconfig.ConfigFile) map[string]string {
	global := make(map[string]string)
	cmds := c.GetKeyList("global")
	for _, v := range cmds {
		row, _ := c.GetValue("global", v)
		global[strings.Trim(v, "#")] = row
	}
	return global
}
开发者ID:benlightning,项目名称:fabux,代码行数:9,代码来源:fabconfig.go


示例5: config

func config(cfg *goconfig.ConfigFile, section string, key string, lvl level) string {
	value, err := cfg.GetValue(section, key)
	if err != nil {
		switch lvl {
		case FATAL:
			logger.Critical("Can't Read config %s", err.Error())
			panic(err.Error())
		case ERROR:
			logger.Error("Can't Read config %s", err.Error())
		case WARMING:
			logger.Warn("Can't Read config %s", err.Error())
		case INFO:
			logger.Info("Can't Read config %s", err.Error())
		}
		return ""
	}
	return value
}
开发者ID:mehulsbhatt,项目名称:TunnelMonitor,代码行数:18,代码来源:config.go


示例6: 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


示例7: NewDaemonFromDirectory

func NewDaemonFromDirectory(cfg *goconfig.ConfigFile) (*Daemon, error) {
	kernel, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Kernel")
	initrd, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Initrd")
	glog.V(0).Infof("The config: kernel=%s, initrd=%s", kernel, initrd)
	vboxImage, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Vbox")
	glog.V(0).Infof("The config: vbox image=%s", vboxImage)
	biface, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bridge")
	bridgeip, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "BridgeIP")
	glog.V(0).Infof("The config: bridge=%s, ip=%s", biface, bridgeip)
	bios, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bios")
	cbfs, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Cbfs")
	glog.V(0).Infof("The config: bios=%s, cbfs=%s", bios, cbfs)
	host, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Host")

	var tempdir = path.Join(utils.HYPER_ROOT, "run")
	os.Setenv("TMPDIR", tempdir)
	if err := os.MkdirAll(tempdir, 0755); err != nil && !os.IsExist(err) {
		return nil, err
	}

	var realRoot = path.Join(utils.HYPER_ROOT, "lib")
	// Create the root directory if it doesn't exists
	if err := os.MkdirAll(realRoot, 0755); err != nil && !os.IsExist(err) {
		return nil, err
	}

	var (
		db_file = fmt.Sprintf("%s/hyper.db", realRoot)
	)
	db, err := daemondb.NewDaemonDB(db_file)
	if err != nil {
		return nil, err
	}

	daemon := &Daemon{
		ID:          fmt.Sprintf("%d", os.Getpid()),
		db:          db,
		Kernel:      kernel,
		Initrd:      initrd,
		Bios:        bios,
		Cbfs:        cbfs,
		VboxImage:   vboxImage,
		PodList:     NewPodList(),
		VmList:      NewVmList(),
		Host:        host,
		BridgeIP:    bridgeip,
		BridgeIface: biface,
	}

	daemon.Daemon, err = docker.NewDaemon(dockerCfg, registryCfg)
	if err != nil {
		return nil, err
	}

	// Get the docker daemon info
	sysinfo, err := daemon.Daemon.SystemInfo()
	if err != nil {
		return nil, err
	}
	stor, err := StorageFactory(sysinfo)
	if err != nil {
		return nil, err
	}
	daemon.Storage = stor
	daemon.Storage.Init()

	return daemon, nil
}
开发者ID:juito,项目名称:hyper,代码行数:68,代码来源:daemon.go


示例8: downloadPackages

// downloadPackages downloads packages with certain commit,
// if the commit is empty string, then it downloads all dependencies,
// otherwise, it only downloada package with specific commit only.
func downloadPackages(ctx *cli.Context, nodes []*doc.Node) {
	// Check all packages, they may be raw packages path.
	for _, n := range nodes {
		// Check if local reference
		if n.Type == doc.LOCAL {
			continue
		}
		// Check if it is a valid remote path or C.
		if n.ImportPath == "C" {
			continue
		} else if !doc.IsValidRemotePath(n.ImportPath) {
			// Invalid import path.
			log.Error("download", "Skipped invalid package: "+fmt.Sprintf("%[email protected]%s:%s",
				n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
			failConut++
			continue
		}

		// Valid import path.
		gopathDir := path.Join(installGopath, n.ImportPath)
		n.RootPath = doc.GetProjectPath(n.ImportPath)
		installPath := path.Join(installRepoPath, n.RootPath) + versionSuffix(n.Value)

		if isSubpackage(n.RootPath, ".") {
			continue
		}

		// Indicates whether need to download package again.
		if n.IsFixed() && com.IsExist(installPath) {
			n.IsGetDepsOnly = true
		}

		if !ctx.Bool("update") {
			// Check if package has been downloaded.
			if (len(n.Value) == 0 && !ctx.Bool("remote") && com.IsExist(gopathDir)) ||
				com.IsExist(installPath) {
				log.Trace("Skipped installed package: %[email protected]%s:%s",
					n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))

				// Only copy when no version control.
				if ctx.Bool("gopath") && com.IsExist(installPath) ||
					len(getVcsName(gopathDir)) == 0 {
					copyToGopath(installPath, gopathDir)
				}
				continue
			} else {
				doc.LocalNodes.SetValue(n.RootPath, "value", "")
			}
		}

		if downloadCache[n.RootPath] {
			log.Trace("Skipped downloaded package: %[email protected]%s:%s",
				n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
			continue
		}

		// Download package.
		nod, imports := downloadPackage(ctx, n)
		if len(imports) > 0 {
			var gf *goconfig.ConfigFile

			// Check if has gopmfile.
			if com.IsFile(installPath + "/" + doc.GOPM_FILE_NAME) {
				log.Log("Found gopmfile: %[email protected]%s:%s",
					n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
				gf = doc.NewGopmfile(installPath)
			}

			// Need to download dependencies.
			// Generate temporary nodes.
			nodes := make([]*doc.Node, len(imports))
			for i := range nodes {
				nodes[i] = doc.NewNode(imports[i], imports[i], doc.BRANCH, "", true)

				if gf == nil {
					continue
				}

				// Check if user specified the version.
				if v, err := gf.GetValue("deps", imports[i]); err == nil && len(v) > 0 {
					nodes[i].Type, nodes[i].Value = validPath(v)
				}
			}
			downloadPackages(ctx, nodes)
		}

		// Only save package information with specific commit.
		if nod == nil {
			continue
		}

		// Save record in local nodes.
		log.Success("SUCC", "GET", fmt.Sprintf("%[email protected]%s:%s",
			n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
		downloadCount++

		// Only save non-commit node.
//.........这里部分代码省略.........
开发者ID:josephyzhou,项目名称:gopm,代码行数:101,代码来源:get.go


示例9: 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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang doc.Package类代码示例发布时间:2022-05-28
下一篇:
Golang goconfig.SaveConfigFile函数代码示例发布时间: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