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

Golang goconf.ConfigFile类代码示例

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

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



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

示例1: GetRequiredString

//convenience function for requiring a string in the config file
func GetRequiredString(config *goconf.ConfigFile, section string, key string) (value string) {
	value, err := config.GetString(section, key)
	if err != nil {
		logger.Fatalf("[CONFIG] %v is required: [section=%v]", key, section)
	}
	return
}
开发者ID:russ168,项目名称:golem,代码行数:8,代码来源:vars.go


示例2: parseConfig

func parseConfig(conf *goconf.ConfigFile) (*config, error) {
	host, err := conf.GetString("database", "host")
	if err != nil || len(host) == 0 {
		return nil, errors.New("empty database host in the config file")
	}
	port, err := conf.GetInt("database", "port")
	if err != nil || port <= 0 || port > 0xFFFF {
		return nil, errors.New("invalid database port in the config file")
	}
	user, err := conf.GetString("database", "user")
	if err != nil || len(user) == 0 {
		return nil, errors.New("empty database user in the config file")
	}
	password, err := conf.GetString("database", "password")
	if err != nil || len(password) == 0 {
		return nil, errors.New("empty database password in the config file")
	}
	dbname, err := conf.GetString("database", "name")
	if err != nil || len(dbname) == 0 {
		return nil, errors.New("empty database name in the config file")
	}

	v := &config{
		hosts:    strings.Split(strings.Replace(host, " ", "", -1), ","),
		port:     uint16(port),
		username: user,
		password: password,
		dbName:   dbname,
	}
	return v, nil
}
开发者ID:yebinMoon,项目名称:cherry,代码行数:31,代码来源:mysql.go


示例3: GlobalLogger

// sets global logger based on verbosity level in configuration
// optional parameter:  default.verbose (defaults to true if not present or incorrectly set)
func GlobalLogger(configFile *goconf.ConfigFile) {
	verbose, err := configFile.GetBool("default", "verbose")
	logger = log4go.NewVerboseLogger(verbose, nil, "")
	if err != nil {
		logger.Warn(err)
		verbose = true
	}
	logger.Printf("verbose set [%v]", verbose)
}
开发者ID:russ168,项目名称:golem,代码行数:11,代码来源:main.go


示例4: ConBufferSize

// Sets global variable to configure buffersize for channels wrapping connections between worker and master (stdout, stderr)
// optional parameters:  master.buffersize
func ConBufferSize(section string, config *goconf.ConfigFile) {
	bufsize, err := config.GetInt(section, "conbuffersize")
	if err != nil {
		logger.Warn(err)
	} else {
		conbuffersize = bufsize
		logger.Printf("conbuffersize=[%v]", conbuffersize)
	}
}
开发者ID:russ168,项目名称:golem,代码行数:11,代码来源:vars.go


示例5: GoMaxProc

//get the number of processors to use for golem itself
func GoMaxProc(section string, config *goconf.ConfigFile) {
	gomaxproc, err := config.GetInt(section, "gomaxproc")
	if err != nil {
		logger.Warn(err)
	} else {
		runtime.GOMAXPROCS(gomaxproc)
		logger.Printf("gomaxproc=[%v]", gomaxproc)
	}
}
开发者ID:russ168,项目名称:golem,代码行数:10,代码来源:vars.go


示例6: cfgOpt

// cfgOpt returns the configuration option from the specified section. If the
// option does not exist an empty string is returned.
func cfgOpt(cfg *conf.ConfigFile, section, option string) string {
	if !cfg.HasOption(section, option) {
		return ""
	}
	s, err := cfg.GetString(section, option)
	if err != nil {
		log.Exitf("Failed to get %s for %s: %v", option, section, err)
	}
	return s
}
开发者ID:Cepave,项目名称:lvs-metrics,代码行数:12,代码来源:main.go


示例7: SubIOBufferSize

// Sets global variable to configure buffersize for master submission channels (stdout, stderr)
// optional parameters:  master.buffersize
func SubIOBufferSize(section string, configFile *goconf.ConfigFile) {
	bufsize, err := configFile.GetInt(section, "subiobuffersize")
	if err != nil {
		logger.Warn(err)
	} else {
		iobuffersize = bufsize
	}

	logger.Printf("buffersize=[%v]", iobuffersize)
}
开发者ID:russ168,项目名称:golem,代码行数:12,代码来源:vars.go


示例8: IOMOnitors

//get the number of IO monitors to run per node
func IOMOnitors(config *goconf.ConfigFile) {
	iomons, err := config.GetInt("master", "iomonitors")
	if err != nil {
		logger.Warn(err)
	} else {
		if iomons > 0 {
			iomonitors = iomons
		}
	}
	logger.Printf("iomonitors=[%v]", iomonitors)
}
开发者ID:russ168,项目名称:golem,代码行数:12,代码来源:vars.go


示例9: StartHtmlHandler

// starts http handlers for HTML content based on the given configuration file
// optional parameters:  default.contentDirectory (location of html content to be served at https://example.com/ or https://example.com/html/index.html
func StartHtmlHandler(configFile *goconf.ConfigFile) {
	if contentDir, _ := configFile.GetString("default", "contentDirectory"); contentDir != "" {
		logger.Printf("StartHtmlHandler(): serving HTML content from [%v]", contentDir)
		http.Handle("/html/", http.StripPrefix("/html/", http.FileServer(http.Dir(contentDir))))
		http.Handle("/", http.RedirectHandler("/html/index.html", http.StatusTemporaryRedirect))
		wd, err := os.Getwd()
		if err == nil {
			http.Handle("/output/", http.StripPrefix("/output/", http.FileServer(http.Dir(wd))))
		}
	}
}
开发者ID:russ168,项目名称:golem,代码行数:13,代码来源:main.go


示例10: StartWorker

// starts worker based on the given configuration file
// required parameters:  worker.masterhost
// optional parameters:  worker.processes
func StartWorker(configFile *goconf.ConfigFile) {

	GoMaxProc("worker", configFile)
	ConBufferSize("worker", configFile)
	processes, err := configFile.GetInt("worker", "processes")
	if err != nil {
		logger.Warn(err)
		processes = 3
	}
	masterhost := GetRequiredString(configFile, "worker", "masterhost")
	logger.Printf("StartWorker() [%v, %d]", masterhost, processes)
	RunNode(processes, masterhost)
}
开发者ID:russ168,项目名称:golem,代码行数:16,代码来源:main.go


示例11: MongoLogger

func MongoLogger(configFile *goconf.ConfigFile) {
	verbose, err := configFile.GetBool("mgodb", "verbose")
	if err != nil {
		logger.Warn(err)
		verbose = false
	}

	logger.Printf("mongo logger verbose set [%v]", verbose)
	if verbose {
		mgo.SetLogger(logger)
		mgo.SetDebug(verbose)
	}
}
开发者ID:russ168,项目名称:golem,代码行数:13,代码来源:main.go


示例12: readDefaultConfig

func (c *Config) readDefaultConfig(readConfigData *goconf.ConfigFile) error {
	var err error

	c.BaseDir, err = readConfigData.GetString("default", "base_dir")
	if err != nil || len(c.BaseDir) == 0 {
		return errors.New("invalid BaseDir directory")
	}
	if c.BaseDir[0] != '/' {
		return errors.New("BaseDir directory should be specified as an absolute path")
	}

	return nil
}
开发者ID:sungsoon0813,项目名称:dbms,代码行数:13,代码来源:config.go


示例13: initConnection

// Initializes a new connection to the given account in a separate goroutine
func initConnection(notify chan bool, conf *goconf.ConfigFile, account string) {
	hostname, _ := conf.GetString(account, "hostname")
	username, _ := conf.GetString(account, "username")
	passexec, _ := conf.GetString(account, "password")

	pw := exec.Command("/bin/sh", "-c", passexec)
	pw.Env = os.Environ()
	pwbytes, err := pw.Output()
	if err != nil {
		fmt.Printf("%s: password command failed: %s\n", account, err)
		return
	}

	password := strings.TrimRight(string(pwbytes), "\n")
	if password == "" {
		fmt.Printf("%s: password command returned an empty string\n", account)
		return
	}

	folder, e := conf.GetString(account, "folder")
	if e != nil {
		folder = "INBOX"
	}

	poll, e := conf.GetInt(account, "poll")
	if e != nil {
		poll = 29
	}
	polli := time.Duration(poll) * time.Minute

	go parts.Connect(notify, account, hostname, username, password, folder, polli)
}
开发者ID:jonhoo,项目名称:hasmail,代码行数:33,代码来源:hasmail.go


示例14: parseRESTConfig

func parseRESTConfig(conf *goconf.ConfigFile) (*restConfig, error) {
	var err error
	c := &restConfig{}

	c.tls.enable, err = conf.GetBool("rest", "tls")
	if err != nil {
		return nil, errors.New("invalid rest/tls value")
	}

	port, err := conf.GetInt("rest", "port")
	if err != nil || port <= 0 || port > 65535 {
		return nil, errors.New("empty or invalid rest/port value")
	}
	c.port = uint16(port)

	c.tls.certFile, err = conf.GetString("rest", "cert_file")
	if err != nil || len(c.tls.certFile) == 0 {
		return nil, errors.New("empty rest/cert_file value")
	}
	if c.tls.certFile[0] != '/' {
		return nil, errors.New("rest/cert_file should be specified as an absolute path")
	}

	c.tls.keyFile, err = conf.GetString("rest", "key_file")
	if err != nil || len(c.tls.keyFile) == 0 {
		return nil, errors.New("empty rest/key_file value")
	}
	if c.tls.keyFile[0] != '/' {
		return nil, errors.New("rest/key_file should be specified as an absolute path")
	}

	return c, nil
}
开发者ID:yebinMoon,项目名称:cherry,代码行数:33,代码来源:controller.go


示例15: readDefaultConfig

func (c *Config) readDefaultConfig(conf *goconf.ConfigFile) error {
	var err error

	c.Port, err = conf.GetInt("default", "port")
	if err != nil || c.Port <= 0 || c.Port > 0xFFFF {
		return errors.New("invalid port in the config file")
	}

	logLevel, err := conf.GetString("default", "log_level")
	if err != nil || len(logLevel) == 0 {
		return errors.New("invalid log level in the config file")
	}
	if err := c.parseLogLevel(logLevel); err != nil {
		return err
	}

	apps, err := conf.GetString("default", "applications")
	if err != nil || len(apps) == 0 {
		return errors.New("empty applications in the config file")
	}
	if err := c.parseApplications(apps); err != nil {
		return fmt.Errorf("invalid applications config: %v", err)
	}

	return nil
}
开发者ID:yebinMoon,项目名称:cherry,代码行数:26,代码来源:config.go


示例16: GlobalTls

// Sets global variable to enable TLS communications and other related variables (certificate path, organization)
// optional parameters:  default.certpath, default.organization, default.tls
func GlobalTls(configFile *goconf.ConfigFile) {
	certificatepath, err := configFile.GetString("default", "certpath")
	if err != nil {
		logger.Warn(err)
	} else {
		certpath = certificatepath
	}
	logger.Printf("certpath=[%v]", certpath)

	certificateorg, err := configFile.GetString("default", "organization")
	if err != nil {
		logger.Warn(err)
		if certificateorg, err = os.Hostname(); err != nil {
			logger.Warn(err)
			certificateorg = "golem.googlecode.com"
		}
	}
	certorg = certificateorg
	logger.Printf("certorg=[%v]", certorg)

	useTlsl, err := configFile.GetBool("default", "tls")
	if err != nil {
		logger.Warn(err)
		useTls = true
	} else {
		useTls = useTlsl
	}
	logger.Printf("TLS=[%v]", useTls)
}
开发者ID:russ168,项目名称:golem,代码行数:31,代码来源:vars.go


示例17: setupAuthHandler

func setupAuthHandler(cfg *goconf.ConfigFile) martini.Handler {
	auth_url, _ := cfg.GetString("Auth", "endpoint")
	hostname, _ := cfg.GetString("Cache", "hostname")
	port, _ := cfg.GetString("Cache", "port")
	password, _ := cfg.GetString("Cache", "password")

	return auth.Keystone(
		auth.IdentityValidator{AuthUrl: auth_url},
		auth.Redis{
			Hostname: hostname,
			Port:     port,
			Password: password,
			Database: int64(0)})
}
开发者ID:yuemin-li,项目名称:gorse,代码行数:14,代码来源:server.go


示例18: StartScribe

// starts scribe service based on the given configuration file
// required parameters:  default.hostname, default.password, scribe.target, mgodb.server, mgodb.store, mgodb.jobcollection, mgodb.taskcollection
func StartScribe(configFile *goconf.ConfigFile) {
	MongoLogger(configFile)

	GoMaxProc("scribe", configFile)

	hostname := GetRequiredString(configFile, "default", "hostname")
	apikey := GetRequiredString(configFile, "default", "password")
	target := GetRequiredString(configFile, "scribe", "target")
	dbhost := GetRequiredString(configFile, "mgodb", "server")
	dbstore := GetRequiredString(configFile, "mgodb", "store")

	url, err := url.Parse(target)
	if err != nil {
		panic(err)
	}

	go LaunchScribe(NewMongoJobStore(dbhost, dbstore), target, apikey)

	rest.Resource("jobs", ScribeJobController{NewMongoJobStore(dbhost, dbstore), url, apikey})
	rest.ResourceContentType("jobs", "application/json")

	rest.Resource("nodes", ProxyNodeController{url, apikey})
	rest.ResourceContentType("nodes", "application/json")

	rest.Resource("cluster", ScribeClusterController{NewMongoJobStore(dbhost, dbstore), url})
	rest.ResourceContentType("cluster", "application/json")

	var numberOfSeconds int = 10
	if pollingSecs, oops := configFile.GetInt("scribe", "clusterStatsPollingInSeconds"); oops == nil {
		numberOfSeconds = pollingSecs
	}

	logger.Printf("polling for cluster stats every %d secs", numberOfSeconds)
	go MonitorClusterStats(NewMongoJobStore(dbhost, dbstore), target, int64(numberOfSeconds))

	ListenAndServeTLSorNot(hostname)
}
开发者ID:russ168,项目名称:golem,代码行数:39,代码来源:main.go


示例19: setValues

func setValues(d *schema.ResourceData, c *goconf.ConfigFile) error {
	buildval, err := c.GetString("default", "COREOS_BUILD")
	if err != nil {
		return err
	}

	branchval, err := c.GetString("default", "COREOS_BRANCH")
	if err != nil {
		return err
	}

	patchval, err := c.GetString("default", "COREOS_PATCH")
	if err != nil {
		return err
	}

	versionval, err := c.GetString("default", "COREOS_VERSION")
	if err != nil {
		return err
	}

	version_idval, err := c.GetString("default", "COREOS_VERSION_ID")
	if err != nil {
		return err
	}

	build_idval, err := c.GetString("default", "COREOS_BUILD_ID")
	if err != nil {
		return err
	}

	sdk_versionval, err := c.GetString("default", "COREOS_SDK_VERSION")
	if err != nil {
		return err
	}

	d.Set("build", buildval)
	d.Set("branch", branchval)
	d.Set("patch", patchval)
	d.Set("version", versionval)
	d.Set("version_id", version_idval)
	d.Set("build_id", build_idval)
	d.Set("sdk_version", sdk_versionval)
	return nil
}
开发者ID:samsung-cnct,项目名称:terraform-provider-coreosver,代码行数:45,代码来源:resource.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang coordinate.WorkSpec类代码示例发布时间:2022-05-23
下一篇:
Golang goconf.ReadConfigFile函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap