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


Golang goconf.ReadConfigFile函数代码示例

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


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

示例1: main

//parse args and start as master, scribe, addama proxy or worker
func main() {
	var configurationFile string
	var isMaster bool
	var isScribe bool
	var isAddama bool

	flag.BoolVar(&isMaster, "m", false, "Start as master node.")
	flag.BoolVar(&isScribe, "s", false, "Start as scribe node.")
	flag.BoolVar(&isAddama, "a", false, "Start as addama node.")
	flag.StringVar(&configurationFile, "config", "golem.config", "A configuration file for golem services")
	flag.Parse()

	configFile, err := goconf.ReadConfigFile(configurationFile)
	if err != nil {
		panic(err)
	}

	GlobalLogger(configFile)
	GlobalTls(configFile)
	SubIOBufferSize("default", configFile)
	GoMaxProc("default", configFile)
	ConBufferSize("default", configFile)
	StartHtmlHandler(configFile)

	if isMaster {
		StartMaster(configFile)
	} else if isScribe {
		StartScribe(configFile)
	} else if isAddama {
		StartAddama(configFile)
	} else {
		StartWorker(configFile)
	}
}
开发者ID:russ168,项目名称:golem,代码行数:35,代码来源:main.go

示例2: GetRedisPool

//get redis connection pool
func GetRedisPool() *redis.Pool {
	if pool == nil {
		pool = &redis.Pool{
			MaxIdle:     3,
			IdleTimeout: 240 * time.Second,
			Dial: func() (redis.Conn, error) {
				conf, err := goconf.ReadConfigFile("auth.conf")
				if err != nil {
					fmt.Println(err)
					return nil, err
				}

				host, _ := conf.GetString("redis", "host")
				port, _ := conf.GetInt("redis", "port")
				redis_server := fmt.Sprintf("%s:%d", host, port)

				c, err := redis.Dial("tcp", redis_server)
				if err != nil {
					return nil, err
				}
				return c, err
			},
			TestOnBorrow: func(c redis.Conn, t time.Time) error {
				_, err := c.Do("PING")
				return err
			},
		}
	}
	return pool
}
开发者ID:zhangbaitong,项目名称:ark-ucenter,代码行数:31,代码来源:utils.go

示例3: NewConfigFile

// NewConfigFile returns a *ConfigFile object from the `filename`
func NewConfigFile(filename string) (*ConfigFile, error) {
	cfg, err := goconf.ReadConfigFile(filename)
	if err != nil {
		return nil, err
	}
	return &ConfigFile{cfg: cfg}, err
}
开发者ID:speedland,项目名称:service,代码行数:8,代码来源:config.go

示例4: NewRegistrar

func NewRegistrar(connectionFilePath string) *Registrar {
	connectionFile, _ := goconf.ReadConfigFile(connectionFilePath)
	host, _ := connectionFile.GetString("Connection", "host")
	apikey, _ := connectionFile.GetString("Connection", "apikey")
	logger.Debug("NewRegistrar(%v):%v,%v", connectionFilePath, host, apikey)
	return &Registrar{host: "https://" + host, apikey: apikey}
}
开发者ID:russ168,项目名称:golem,代码行数:7,代码来源:addama.go

示例5: GetDB

//Get db connection from mysql
func GetDB() (db *sql.DB) {
	if DBpool == nil {
		conf, err := goconf.ReadConfigFile("auth.conf")
		if err != nil {
			fmt.Println(err)
			return nil
		}

		host, _ := conf.GetString("mysql", "host")
		port, _ := conf.GetInt("mysql", "port")
		user, _ := conf.GetString("mysql", "user")
		password, _ := conf.GetString("mysql", "password")
		db, _ := conf.GetString("mysql", "db")
		db_server := fmt.Sprintf("%s:%[email protected](%s:%d)/%s", user, password, host, port, db)

		DBpool = CreateDbPool(20, "mysql", db_server, true)
	}

	conn, err := DBpool.GetConn()
	if err != nil {
		fmt.Println(err)
		return nil
	}

	return conn
}
开发者ID:zhangbaitong,项目名称:ark-ucenter,代码行数:27,代码来源:utils.go

示例6: load

func (config *config) load() (err error) {
	if config.HasPath() {
		config.ConfigFile, err = conf.ReadConfigFile(config.Path())
		if err != nil {
			return
		}
	} else {
		config.ConfigFile = conf.NewConfigFile()
	}
	if config.HasDefaultPath() {
		// Load defaults if a path was given.
		config.Defaults, err = conf.ReadConfigFile(config.DefaultPath())
		if err != nil {
			return
		}
	}
	if config.HasOverridePath() {
		// Load overrides if a path was given.
		config.Overrides, err = conf.ReadConfigFile(config.OverridePath())
		if err != nil {
			return
		}
	}

	for _, section := range config.Defaults.GetSections() {
		options, _ := config.Defaults.GetOptions(section)
		for _, option := range options {
			if !config.ConfigFile.HasOption(section, option) {
				value, _ := config.Defaults.GetRawString(section, option)
				config.ConfigFile.AddOption(section, option, value)
			}
		}
	}

	for _, section := range config.Overrides.GetSections() {
		options, _ := config.Overrides.GetOptions(section)
		for _, option := range options {
			value, _ := config.Overrides.GetRawString(section, option)
			config.ConfigFile.AddOption(section, option, value)
		}
	}

	return
}
开发者ID:strukturag,项目名称:phoenix,代码行数:44,代码来源:config.go

示例7: Read

func (c *Config) Read() error {
	readConfigData, err := goconf.ReadConfigFile(*configFile)
	if err != nil {
		return fmt.Errorf("failed to read the config file: %v", err)
	}

	if err := c.readDefaultConfig(readConfigData); err != nil {
		return err
	}

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

示例8: main

func main() {
	flag.Parse()

	cfg, err := conf.ReadConfigFile(*configFile)
	if err != nil {
		log.Fatalf("Failed to read config file %q: %v", *configFile, err)
	}

	fido := watchdog.NewWatchdog()
	server.ShutdownHandler(fido)

	for _, name := range cfg.GetSections() {
		if name == "default" {
			continue
		}

		binary := svcOpt(cfg, name, "binary", true)
		args := svcOpt(cfg, name, "args", false)

		svc, err := fido.AddService(name, binary)
		if err != nil {
			log.Fatalf("Failed to add service %q: %v", name, err)
		}
		svc.AddArgs(args)
		if dep := svcOpt(cfg, name, "dependency", false); dep != "" {
			svc.AddDependency(dep)
		}
		if opt := svcOpt(cfg, name, "priority", false); opt != "" {
			prio, err := strconv.Atoi(opt)
			if err != nil {
				log.Fatalf("Service %s has invalid priority %q: %v", name, opt, err)
			}
			if err := svc.SetPriority(prio); err != nil {
				log.Fatalf("Failed to set priority for service %s: %v", name, err)
			}
		}
		if opt := svcOpt(cfg, name, "term_timeout", false); opt != "" {
			tt, err := time.ParseDuration(opt)
			if err != nil {
				log.Fatalf("Service %s has invalid term_timeout %q: %v", name, opt, err)
			}
			svc.SetTermTimeout(tt)
		}
		// TODO(angusc): Add support for a "group" option.
		if user := svcOpt(cfg, name, "user", false); user != "" {
			if err := svc.SetUser(user); err != nil {
				log.Fatalf("Failed to set user for service %s: %v", name, err)
			}
		}
	}

	fido.Walk()
}
开发者ID:Cepave,项目名称:lvs-metrics,代码行数:53,代码来源:main.go

示例9: Read

func (c *Config) Read() error {
	conf, err := goconf.ReadConfigFile(*configFile)
	if err != nil {
		return err
	}
	c.conf = conf

	if err := c.readDefaultConfig(conf); err != nil {
		return err
	}

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

示例10: getdb

func getdb() *sql.DB {
	var settings, herokupg, localpg string
	herokupg = os.Getenv("DATABASE_URL")
	if herokupg != "" {
		settings, _ = pq.ParseURL(herokupg)
	} else {
		c, _ := goconf.ReadConfigFile("db.config")
		localpg, _ = c.GetString("dev", "postgresurl")
		settings, _ = pq.ParseURL(localpg)
	}
	db, _ := sql.Open("postgres", settings)
	return db
}
开发者ID:stehem,项目名称:plenty_of_links,代码行数:13,代码来源:plenty.go

示例11: parseConfigFile

func (c *config) parseConfigFile() (err error) {
	if c.cfg, err = ini.ReadConfigFile(c.file); err != nil {
		return
	}
	if c.dsn, err = c.cfg.GetString("mysql", "dsn"); err != nil {
		return
	}
	if c.extendedInsRows, err = c.cfg.GetInt("mysql", "extended_insert_rows"); err != nil {
		c.extendedInsRows = 100
	}
	if c.useTableLock, err = c.cfg.GetBool("mysql", "use_table_lock"); err != nil {
		c.useTableLock = true
	}
	if c.maxOpenConns, err = c.cfg.GetInt("mysql", "max_open_conns"); err != nil {
		c.maxOpenConns = 50
	}
	var selects []string
	if selects, err = c.cfg.GetOptions("select"); err != nil {
		return
	}
	for _, tableCol := range selects {
		var table, column string
		if table, column, err = c.splitTableColumn(tableCol); err != nil {
			return
		}
		if c.selectMap[table] == nil {
			c.selectMap[table] = make(map[string]string, 0)
		}
		if c.selectMap[table][column], err = c.cfg.GetString("select", tableCol); err != nil {
			return
		}
	}
	if c.loadOptions("where", c.whereMap); err != nil {
		return
	}
	if c.loadOptions("filter", c.filterMap); err != nil {
		return
	}
	return
}
开发者ID:aquilaphp,项目名称:mysqlsuperdump,代码行数:40,代码来源:config.go

示例12: initializeBotsFromConfig

func initializeBotsFromConfig(configPath string) []*jarvis.Bot {
	bots := []*jarvis.Bot{}
	config, err := goconf.ReadConfigFile(configPath)
	if err != nil {
		fmt.Printf("error reading config: %v\n", err)
		os.Exit(1)
	}

	for _, section := range config.GetSections() {
		tokenRaw, err := config.GetString(section, "SLACK_API_TOKEN")
		if err == nil {
			decryptedToken, err := decryptValue(tokenRaw)
			if err != nil {
				fmt.Printf("error decrypting slack token: %v\n", err)
				os.Exit(1)
			}
			j := jarvis.NewBot(decryptedToken)

			options, _ := config.GetOptions(section)
			for _, option := range options {
				if value, err := config.GetString(section, option); err == nil {
					decryptedValue, err := decryptValue(value)
					if err == nil {
						j.Configuration()[strings.ToUpper(option)] = decryptedValue
					} else {
						j.Configuration()[strings.ToUpper(option)] = value
					}
				}
			}

			j.Init()
			j.Start()
			bots = append(bots, j)
		} else {
			fmt.Printf("Error Reading `SLACK_API_TOKEN`: %v\n", err)
		}
	}
	return bots
}
开发者ID:wcharczuk,项目名称:jarvis,代码行数:39,代码来源:main.go

示例13: GetSession

func GetSession() (Session *mgo.Session) {
	if MPool == nil {
		conf, err := goconf.ReadConfigFile("auth.conf")
		if err != nil {
			fmt.Println(err)
			return nil
		}

		host, _ := conf.GetString("mongodb", "host")
		port, _ := conf.GetInt("mongodb", "port")
		mongo_server := fmt.Sprintf("%s:%d", host, port)

		MPool = CreateMongoPool(20, mongo_server)
	}

	Session, err := MPool.GetSession()
	if err != nil {
		fmt.Println(err)
		return nil
	}

	return Session
}
开发者ID:zhangbaitong,项目名称:ark-ucenter,代码行数:23,代码来源:utils.go

示例14: read_conf

func read_conf() {
	conf, err := goconf.ReadConfigFile("auth.conf")
	if err != nil {
		fmt.Println(err)
	}
	cert, _ = conf.GetString("server", "cert")
	key, _ = conf.GetString("server", "key")
	https_port, _ = conf.GetInt("server", "https_port")
	port, _ = conf.GetInt("server", "port")
	ValidTime, _ := conf.GetInt("sms", "valid_time")
	action.ValidTime = int64(ValidTime)
	RefreshTime, _ := conf.GetInt("sms", "refresh_time")
	action.RefreshTime = int64(RefreshTime)

	sms_host, _ := conf.GetString("sms", "host")
	action.SMSHost = sms_host
	str_key, _ := conf.GetString("sms", "key")
	action.TnterfaceKey = str_key
	str_sign, _ := conf.GetString("sms", "sign")
	action.InterfaceSign = str_sign
	check_text, _ := conf.GetString("sms", "check_text")
	action.CheckText = check_text

}
开发者ID:zhangbaitong,项目名称:ark-ucenter,代码行数:24,代码来源:main.go

示例15: InitConfig

// parse the configuration file, returning any error encountered
func InitConfig(file string) (err error) {
	rc, err = gc.ReadConfigFile(file)
	return
}
开发者ID:deong,项目名称:GoRL,代码行数:5,代码来源:conf.go


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