當前位置: 首頁>>代碼示例>>Golang>>正文


Golang goconfig.ReadConfigFile函數代碼示例

本文整理匯總了Golang中github.com/msbranco/goconfig.ReadConfigFile函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReadConfigFile函數的具體用法?Golang ReadConfigFile怎麽用?Golang ReadConfigFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ReadConfigFile函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: init

func init() {
	flag.Parse()
	c, err := goconfig.ReadConfigFile("config")
	if err != nil {
		glog.Warningf("init(): readconfigfile(config)")
		oauthCfg.ClientSecret = "a"
		oauthCfg.ClientId = "b"
		MyURL = "c"
		oauthCfg.RedirectURL = "d"
		return
	}
	oauthCfg.ClientId, err = c.GetString("Google", "ClientId")
	if err != nil {
		glog.Fatal("init(): readconfigfile(Google.ClientId), using dummy")
	}
	oauthCfg.ClientSecret, err = c.GetString("Google", "ClientSecret")
	if err != nil {
		glog.Fatal("init(): readconfigfile(Google.ClientSecret)")
	}
	url, err := c.GetString("Web", "url")
	MyURL = url
	if err != nil {
		glog.Fatal("init(): readconfigfile(Web.url)")
	}
	oauthCfg.RedirectURL = url + "/oauth2callback"
}
開發者ID:ChrisKaufmann,項目名稱:feedinator-go,代碼行數:26,代碼來源:auth.go

示例2: ReadConf

func (conf *Config) ReadConf(file string) (*Config, error) {
	if file == "" {
		file = filepath.Join(DEFAULT_CONF_PATH, DEFAULT_CONF)
	}

	c, err := goconf.ReadConfigFile(file)
	if err != nil {
		return nil, err
	}

	//TODO: check
	conf.log, _ = c.GetString("default", "log")
	conf.level, _ = c.GetString("default", "level")
	conf.topic, _ = c.GetString("default", "topic")
	conf.kaddr, _ = c.GetString("default", "kafka_addr")
	conf.sport, _ = c.GetString("default", "ssh_port")
	conf.suser, _ = c.GetString("default", "ssh_user")
	conf.skey, _ = c.GetString("default", "ssh_key")
	conf.sto, err = c.GetInt64("default", "ssh_timeout")
	if err != nil {
		conf.sto = DEFAULT_SSH_TIMEOUT
	}
	conf.daemon, _ = c.GetBool("default", "daemon")

	return conf, nil
}
開發者ID:wxjs33,項目名稱:kfkcp,代碼行數:26,代碼來源:conf.go

示例3: init

func init() {
	var err error
	flag.Parse()
	c, err := goconfig.ReadConfigFile("../config")
	db_name, err := c.GetString("DB", "db")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.db): %s", err)
	}
	db_host, err := c.GetString("DB", "host")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.Host): %s", err)
	}
	db_user, err := c.GetString("DB", "user")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.user): %s", err)
	}
	db_pass, err := c.GetString("DB", "pass")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.pass): %s", err)
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@tcp("+db_host+")/"+db_name)
	if err != nil {
		glog.Fatalf("Init():sql.Open(mysql, %s:%[email protected]%s/%s: %s", db_user, db_pass, db_host, db_name, err)
	}
	ebay_application_id, err = c.GetString("Ebay", "ApplicationID")
	if err != nil {
		glog.Fatalf("init():Config.GetString(Ebay,ApplicationID): %s", err)
	}
	eb = ebay.New(ebay_application_id)
	ebay_url, err := c.GetString("Ebay", "URL")
	if err == nil {
		eb.URL = ebay_url
	}
}
開發者ID:ChrisKaufmann,項目名稱:gameslist,代碼行數:34,代碼來源:bidder.go

示例4: init

func init() {
	var err error
	flag.Parse()
	c, err := goconfig.ReadConfigFile("config")
	if port, err = c.GetString("Web", "port"); err != nil {
		glog.Fatalf("init(): config.GetString(web.portal): %s", err)
	}
	if environment, err = c.GetString("Web", "environment"); err != nil {
		glog.Fatalf("init(): config.GetString(Web.environment): %s", err)
	}
	db_name, err := c.GetString("DB", "db")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.db): %s", err)
	}
	db_host, err := c.GetString("DB", "host")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.Host): %s", err)
	}
	db_user, err := c.GetString("DB", "user")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.user): %s", err)
	}
	db_pass, err := c.GetString("DB", "pass")
	if err != nil {
		glog.Fatalf("init(): config.GetString(DB.pass): %s", err)
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@tcp("+db_host+")/"+db_name)
	if err != nil {
		glog.Fatalf("Init():sql.Open(mysql, %s:%[email protected]%s/%s: %s", db_user, db_pass, db_host, db_name, err)
	}
	cookieName = "gameslist_auth_" + environment
	auth.Config("config")
	auth.CookieName(cookieName)
	auth.Environment(environment)
}
開發者ID:ChrisKaufmann,項目名稱:gameslist,代碼行數:35,代碼來源:main.go

示例5: ReadOptions

func ReadOptions(fpath string) {
	c, err := goconfig.ReadConfigFile(fpath)
	if err != nil {
		panic("Could not read config.cfg at " + fpath)
	}
	UseRadians, err = c.GetBool("math", "UseRadians")
	if err != nil {
		panic("Bad config statement UseRadians")
	}
	SigFigs, err = c.GetInt64("math", "SignificantFigures")
	if err != nil {
		panic("Bad config statement SignificantFigures")
	}
	UseColoredOutput, err = c.GetBool("latex", "UseColoredOutput")
	if err != nil {
		panic("Bad config statement UseColoredOutput")
	}
	OutputColor, err = c.GetString("latex", "OutputColor")
	if err != nil {
		panic("Bad config statement OutputColor")
	}
	OrSymbol, err = c.GetString("latex", "OrSymbol")
	if err != nil {
		panic("Bad config statement OrSymbol")
	}
	DefinitionSymbol, err = c.GetString("latex", "DefinitionSymbol")
	if err != nil {
		panic("Bad config statement DefinitionSymbol")
	}
}
開發者ID:Englebabz,項目名稱:CasGO,代碼行數:30,代碼來源:configparser.go

示例6: NewFromConfigFile

func NewFromConfigFile(file string, client bool) Mgollective {
	conf, err := goconfig.ReadConfigFile(file)
	if err != nil {
		log.Fatal("Couldn't open config ", err)
	}

	mgo := Mgollective{
		logger: seelog.Disabled,
		client: client,
		config: *conf,
	}

	connectorname := mgo.GetStringDefault("connector", "class", "redis")

	if factory, exists := connectorRegistry[connectorname]; exists {
		mgo.Connector = factory(&mgo)
	} else {
		fmt.Printf("No connector called %s", connectorname)
		panic("panic")
	}

	mgo.Connector.Connect()
	mgo.Connector.Subscribe()

	return mgo
}
開發者ID:richardc,項目名稱:mgollective,代碼行數:26,代碼來源:mgollective.go

示例7: init

func init() {
	var err error
	c, err := goconfig.ReadConfigFile("config")
	if err != nil {
		err.Error()
	}
	db_name, err = c.GetString("DB", "db")
	if err != nil {
		err.Error()
	}
	db_host, err = c.GetString("DB", "host")
	if err != nil {
		err.Error()
	}
	db_user, err = c.GetString("DB", "user")
	if err != nil {
		err.Error()
	}
	db_pass, err = c.GetString("DB", "pass")
	if err != nil {
		err.Error()
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@"+db_host+"/"+db_name)
	if err != nil {
		panic(err)
	}
}
開發者ID:ChrisKaufmann,項目名稱:groptimizer-go,代碼行數:27,代碼來源:db.go

示例8: Config

func Config(config string) {
	c, err := goconfig.ReadConfigFile(config)
	googleEnabled = true
	facebookEnabled = true
	if err != nil {
		glog.Fatalf("init(): readconfigfile(config)")
	}
	GoogOauthCfg.ClientID, err = c.GetString("Google", "ClientID")
	if err != nil {
		googleEnabled = false
		glog.Errorf("init(): readconfigfile(Google.ClientID)")
	}
	GoogOauthCfg.ClientSecret, err = c.GetString("Google", "ClientSecret")
	if err != nil {
		googleEnabled = false
		glog.Errorf("init(): readconfigfile(Google.ClientSecret)")
	}
	FBOauthCfg.ClientID, err = c.GetString("Facebook", "ClientID")
	if err != nil {
		facebookEnabled = false
		glog.Errorf("init(): readconfigfile(Facebook.ClientID)")
	}
	FBOauthCfg.ClientSecret, err = c.GetString("Facebook", "ClientSecret")
	if err != nil {
		facebookEnabled = false
		glog.Errorf("init(): readconfigfile(Facebook.ClientSecret)")
	}
	url, err := c.GetString("Web", "url")
	MyURL = url
	if err != nil {
		glog.Fatalf("init(): readconfigfile(Web.url)")
	}
	GoogOauthCfg.RedirectURL = url + "oauth2callback"
	FBOauthCfg.RedirectURL = url + "fboauth2callback"
}
開發者ID:ChrisKaufmann,項目名稱:goauth,代碼行數:35,代碼來源:auth.go

示例9: new_address_matcher

func new_address_matcher() *address_matcher {
	// honor NOTMUCH_CONFIG
	home := os.Getenv("NOTMUCH_CONFIG")
	if home == "" {
		home = os.Getenv("HOME")
	}

	cfg, err := goconfig.ReadConfigFile(path.Join(home, ".notmuch-config"))
	if err != nil {
		log.Fatalf("error loading config file:", err)
	}

	db_path, _ := cfg.GetString("database", "path")
	primary_email, _ := cfg.GetString("user", "primary_email")
	addrbook_tag, err := cfg.GetString("user", "addrbook_tag")
	if err != nil {
		addrbook_tag = "addressbook"
	}

	self := &address_matcher{db: nil,
		user_db_path:       db_path,
		user_primary_email: primary_email,
		user_addrbook_tag:  addrbook_tag}
	return self
}
開發者ID:avdv,項目名稱:notmuch-w32,代碼行數:25,代碼來源:addrlookup.go

示例10: initGame

func initGame() {
	g, err := goconfig.ReadConfigFile("test_config")
	db_name, err := g.GetString("DB", "db")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db_host, err := g.GetString("DB", "host")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db_user, err := g.GetString("DB", "user")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db_pass, err := g.GetString("DB", "pass")
	if err != nil {
		err.Error()
		fmt.Println(err)
	}
	db, err = sql.Open("mysql", db_user+":"+db_pass+"@tcp("+db_host+")/"+db_name)
	if err != nil {
		panic(err)
	}
	out, err := exec.Command("sh", "create_tables.sh").Output()
	if err != nil {
		glog.Errorf("sh create_tables.sh %s\n%s", err, out)
		return
	}

	ConsoleDB(db)
	GameDB(db)
}
開發者ID:ChrisKaufmann,項目名稱:gameslist,代碼行數:35,代碼來源:game_test.go

示例11: parseConfig

func parseConfig() {
	VERSION = "0.1.0.beta.5"
	c, _ := goconfig.ReadConfigFile("config.ini")
	nats_uri, _ = c.GetString("statistics", "nats_uri")
	logname, _ := c.GetString("logging", "file")
	logfile, err := os.OpenFile(logname, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0660)

	if err != nil {
		fmt.Printf("%s\r\n", err.Error())
	}

	logger = log.New(logfile, "\r", log.Ldate|log.Ltime)

	//debug config
	debug, _ := c.GetBool("debug", "enable")
	node, _ := c.GetString("debug", "debug_node")
	debug_node = node
	fmt.Println(debug_node)

	//puller config
	ft, _ := c.GetInt64("puller", "fetch_interval")
	fetch_interv = time.Duration(ft)
	varz_user, _ := c.GetString("puller", "varz_user")
	varz_pswd, _ := c.GetString("puller", "varz_pswd")
	varz_api, _ := c.GetString("puller", "varz_api")
	varz_port, _ := c.GetInt64("puller", "varz_port")
	node_addr, _ = localIP(debug)
	varz_uri = fmt.Sprintf("http://%s:%[email protected]%s:%d/%s", varz_user,
		varz_pswd, node_addr, varz_port, varz_api)

	//sender config
	nt, _ := c.GetInt64("sender", "node_data_interval")
	ut, _ := c.GetInt64("sender", "instance_data_interval")
	isd, _ := c.GetInt64("sender", "instance_data_delay")
	collector_send_interv = time.Duration(ut)
	node_interv = time.Duration(nt)
	instance_data_delay = time.Duration(isd)

	//checker config
	it, _ := c.GetInt64("checker", "instance_interval")
	ic, _ := c.GetInt64("checker", "instance_check_delay")
	instance_check_interv = time.Duration(it)
	instance_check_delay = time.Duration(ic)

	//collector config
	col_addr, _ := c.GetString("collector", "address")
	base_full_data_api, _ := c.GetString("collector", "full_data_api")
	base_incre_data_api, _ := c.GetString("collector", "incre_data_api")
	base_node_data_api, _ := c.GetString("collector", "node_data_api")
	base_ins_check_api, _ := c.GetString("collector", "ins_check_api")
	ctm, _ := c.GetInt64("collector", "conn_timeout")
	rwtm, _ := c.GetInt64("collector", "rw_timeout")
	full_data_api = col_addr + base_full_data_api
	incre_data_api = col_addr + base_incre_data_api
	node_data_api = col_addr + base_node_data_api
	ins_check_api = col_addr + base_ins_check_api
	conn_timeout = time.Duration(ctm)
	rw_timeout = time.Duration(rwtm)
}
開發者ID:jackytu,項目名稱:data-agent,代碼行數:59,代碼來源:config.go

示例12: getConfig

func getConfig() *goconfig.ConfigFile {
	confFile := filepath.Join(assetDir(), "gits3.ini")
	conf, err := goconfig.ReadConfigFile(confFile)
	if err != nil {
		log.Fatal(err)
	}
	return conf
}
開發者ID:hasegawa-takasei,項目名稱:git-largefile,代碼行數:8,代碼來源:gits3.go

示例13: initPool

func initPool() {
	configs, err := goconfig.ReadConfigFile(configFileName)

	if err != nil {
		logger.Criticalf("Can not read nsq configs from %s. Error: %s", configFileName, err)
		panic(err)
	}

	options, err := configs.GetOptions(nsqdConfigSection)

	if err != nil {
		logger.Criticalf("Can not read nsqd config in %s. Error: $s", configFileName, err)
		panic(err)
	}

	addrs := make([]string, 0, len(options))

	for _, option := range options {
		value, err := configs.GetString(nsqdConfigSection, option)

		if err != nil {
			logger.Errorf("Get error when reading section %s option %s in %s. Error: %s", nsqdConfigSection, option, configFileName, err)
			continue
		}

		addrs = append(addrs, value)
	}

	if len(addrs) <= 0 {
		logger.Criticalf("Read 0 configs for nsqd address in %s.", configFileName)
		panic("Read 0 configs for nsqd address in config file " + configFileName)
	}

	pool = make(map[string]*gonsq.Producer)
	lostConns = make([]string, 0)

	for _, addr := range addrs {
		config := gonsq.NewConfig()
		producer, err := gonsq.NewProducer(addr, config)

		if err != nil {
			logger.Errorf("Can not create nsq producer for address: %s. Error: %s", addr, err)
			continue
		}

		err = producer.Ping()

		if err != nil {
			logger.Errorf("Can not connect to address %s. Error: %s", addr, err)
			lostConns = append(lostConns, addr)
		}

		pool[addr] = producer
	}

	go autoReconnect()
}
開發者ID:hechel,項目名稱:linbox,代碼行數:57,代碼來源:nsq_productioin_pool.go

示例14: ParseConfig

func ParseConfig() APPLICATION_MODE {
	var aws_config_file string
	var base_config_file string
	var register bool
	var send bool
	var input_file string
	var output_file string
	var message_file string

	flag.StringVar(&base_config_file, "baseConfig", "./config/base.conf", "The path to the base configuration file")
	flag.StringVar(&aws_config_file, "awsConfig", "./config/aws.conf", "The path to the aws configuration file")

	flag.BoolVar(&register, "register", false, "Set flag to run in client mode and register a set of devices. If true inputFile and outputFile must be set.")
	flag.BoolVar(&send, "send", false, "Set flag to run in client mode and send push notifications to a set of arns. If true inputFile and outputFile must be set.")

	flag.StringVar(&input_file, "inputFile", "", "The path to the Device IDs or Arns file")
	flag.StringVar(&output_file, "outputFile", "", "The path to the Device IDs or Arns file")
	flag.StringVar(&message_file, "messageFile", "", "The path to the file containing the notificaito message to be sent out")

	flag.Parse()

	log.Printf("Using base configuration file: %s", base_config_file)
	baseConfig, err := goconfig.ReadConfigFile(base_config_file)
	checkError("Unable to parse base config", err)

	log.Printf("Using aws configuration file: %s", aws_config_file)
	awsConfig, err := goconfig.ReadConfigFile(aws_config_file)
	checkError("Unable to parse AWS config", err)

	parseBaseConfig(baseConfig)
	parseAwsConfig(awsConfig)

	if register {
		log.Printf("Running in client mode, registering devices listed in %s, and printing arns in %s", input_file, output_file)
		return REGISTER_MODE
	} else if send {
		log.Printf("Running in client mode, sending pusn notes to ARNs listed in %s, and printing results in %s", input_file, output_file)
		return SEND_MODE
	} else {
		log.Printf("Running in server mode")
		return SERVER_MODE
	}

}
開發者ID:usmanismail,項目名稱:gpns,代碼行數:44,代碼來源:parser.go

示例15: ConfigFile

func ConfigFile() {
	c, err := goconfig.ReadConfigFile("config.cfg")
	if err != nil {
		fmt.Println(err)
	}

	RedisAddress, _ = c.GetString("Redis", "RedisAddress")
	RedisPort, _ = c.GetString("Redis", "RedisPort")
	ESAPI, _ = c.GetString("ES", "API")
	//fmt.Println(RedisAddress + ":" + RedisPort + ":" + ESAPI)
}
開發者ID:jackwanger,項目名稱:PangoLinManage,代碼行數:11,代碼來源:Config.go


注:本文中的github.com/msbranco/goconfig.ReadConfigFile函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。