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

Golang goconf.ReadConfigFile函数代码示例

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

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



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


示例16: main

func main() {
	// Begin here.
	/* -------------------------------------  */
	/* 			Boilerplate					  */
	/* -------------------------------------  */
	/*
		Setting up Logging, this is standard practice for all go programs
	*/
	pwd, err := os.Getwd() // get present working directory
	if err != nil {
		log.Fatal(err)
	}
	fo, err := os.Create(pwd + string(filepath.Separator) + "server.log") // create log file in current dir
	if err != nil {
		log.Fatal(err)
	}
	log.SetOutput(io.Writer(fo))
	// 		Done setting up Logging

	// Initialize the config variables
	// This is triggered only once and loads up the conf file.
	if func() bool {
		_confMap = make(map[string]string)
		pwd, err := os.Getwd() // get present working directory
		if err != nil {
			log.Fatal(err)
		}
		path := pwd + string(filepath.Separator) + "cockpit" + string(filepath.Separator) + "conf"
		_, err = os.Stat(path)
		if err != nil {
			log.Fatal("Config file not found. Config file is located in same directory as executable in a folder .arwen/config")
		}
		_cfile, err = goconf.ReadConfigFile(path)
		if err != nil {
			log.Fatal("Error reading config file." + err.Error())
		}
		return true
	}() {
		log.Print("Loaded Logging, starting up server ...")
	} else {
		log.Fatal("Error loading conf file ...")
	}

	/* -------------------------------------  */
	/*			Coding Begins				  */
	/* -------------------------------------  */
	//Variable stores everything
	_store = make(map[string]interface{})
	_servers = make(map[string]interface{})
	// Channels to manage data
	httpChannel := make(chan map[string]interface{})                       // {action : {object}}
	poller := time.NewTicker(time.Duration(int64(5) * int64(time.Second))) // Actual time variable that is a counter
	alertChannel := make(chan map[string]string)
	pollerChannel := make(chan map[string]interface{})
	//serverChannel := make(chan []Serv)
	HTTPHandler.Init()

	// Load the contents of the servers.json to the _servers
	file, e := ioutil.ReadFile("./cockpit/servers.json")
	if e != nil {
		log.Fatal("File Error")
	}
	log.Print(file)
	if string(file) != "" {
		err = json.Unmarshal(file, &_servers)
		if err != nil {
			log.Fatal("Error reading servers.json")
		}
	}

	// Initiate HTTP Listener
	// Listener for the incoming HTTP request
	go func(store map[string]interface{}, servers map[string]interface{}, ch chan map[string]interface{}) {
		// Define the http listener
		router := mux.NewRouter()
		// ROUTER
		router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			w.Write([]byte("{\"status\":\"alive\"}"))
		})
		router.HandleFunc("/auth", func(w http.ResponseWriter, r *http.Request) {
			HTTPHandler.Auth(w, r)
		})
		router.HandleFunc("/add/{action}", func(w http.ResponseWriter, r *http.Request) {
			HTTPHandler.Add(w, r, ch)
		})
		router.HandleFunc("/server/{action}", func(w http.ResponseWriter, r *http.Request) {
			HTTPHandler.Server(w, r, servers, store)
		})
		router.HandleFunc("/alert", func(w http.ResponseWriter, r *http.Request) {
			// TODO : Put a conditional key here, we need that key to verify that message isn't bogus
			// If a message is recieved on this func, this needs to be sent as an alert ASAP
			log.Print("Message recieved")
			serv := r.FormValue("alert")
			err := r.FormValue("error")
			res := make(map[string]string)
			res["server"] = serv
			res["error"] = err
			alertChannel <- res
			w.Write([]byte("{\"status\":\"posted\"}"))
		})
//.........这里部分代码省略.........
开发者ID:uknth,项目名称:cockpit,代码行数:101,代码来源:main.go


示例17: NewConfig

func NewConfig(filepath string) (*Config, error) {
	config := Config{
		configFilePath: filepath,
	}

	c, err := goconf.ReadConfigFile(filepath)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, errors.New("Could not find config file. Try using the --config=\"<path-to-config-file>\" option to specify a config file.")
		} else {
			return nil, err
		}
	}

	// Change our working directory to that of the config file so that paths referenced in the config file are relative to that location
	err = os.Chdir(path.Dir(filepath))
	if err != nil {
		return nil, err
	}

	// Parse port
	config.port, err = c.GetInt("", "port")
	if err != nil {
		return nil, err
	}

	// Parse database config options
	config.database.host, err = c.GetString("database", "host")
	if err != nil {
		return nil, err
	}
	config.database.port, err = c.GetInt("database", "port")
	if err != nil {
		return nil, err
	}
	config.database.user, err = c.GetString("database", "user")
	if err != nil {
		return nil, err
	}
	config.database.password, err = c.GetString("database", "password")
	if err != nil {
		return nil, err
	}
	config.database.dbname, err = c.GetString("database", "dbname")
	if err != nil {
		return nil, err
	}
	config.database.sslmode, err = c.GetString("database", "sslmode")
	if err != nil {
		return nil, err
	}
	if c.HasOption("database", "max_idle_connections") {
		config.database.maxIdleConnections, err = c.GetInt("database", "max_idle_connections")
		if err != nil {
			return nil, err
		}
	} else {
		config.database.maxIdleConnections = -1
	}

	// Ingest the private key into the global config object
	config.signingKeyPath, err = c.GetString("", "signing-key")
	if err != nil {
		return nil, err
	}
	signingKeyPEM, err := ioutil.ReadFile(config.signingKeyPath)
	if err != nil {
		return nil, err
	}
	config.signingKey, err = NewPrivateKey(signingKeyPEM)
	if err != nil {
		return nil, err
	}

	// Ingest administrators
	config.adminKeysPath, err = c.GetString("", "admins")
	if err != nil {
		return nil, err
	}
	adminPEMBytes, err := ioutil.ReadFile(config.adminKeysPath)
	if err != nil {
		return nil, err
	}
	config.adminUsers, err = NewUserSet(adminPEMBytes)
	if err != nil {
		return nil, err
	}

	// Ingest the readme
	config.readmePath, err = c.GetString("", "readme")
	if err != nil {
		return nil, err
	}
	config.readme, err = ioutil.ReadFile(config.readmePath)
	if err != nil {
		return nil, err
	}

	return &config, nil
}
开发者ID:laprice,项目名称:cryptoballot,代码行数:100,代码来源:bootstrap.go


示例18: main

func main() {
	cfg, err := goconf.ReadConfigFile("rse.config")
	if err != nil {
		panic(err)
	}

	m := martini.Classic()

	auth_handler := setupAuthHandler(cfg)

	m.Handlers(
		auth_handler,
		martini.Recovery(),
	)

	m.Get("/**", func(request *http.Request, params martini.Params, response http.ResponseWriter) string {
		topic := params["_1"]
		marker, marker_present := request.URL.Query()["marker"]

		// Get message from storage
		// if marker_present {
		//     storage.Get(topic, marker)
		// } else {
		//     storage.Get(topic)
		// }

		// Example return
		events := make([]map[string]string, 0)
		event := make(map[string]string)
		event["property"] = "value"
		events = append(events, event)
		jsonString, _ := json.Marshal(events)
		fmt.Println("Events: " + string(jsonString))

		tempReturn := "Getting messages on " + topic
		if marker_present {
			tempReturn += " with marker of " + marker[0]
		}
		// fmt.Println(tempReturn)
		// return tempReturn + "\r\n"

		response.Header()["Content-Type"] = []string{"application/json"}
		return string(jsonString) + "\r\n"
	})

	m.Post("/**", func(request *http.Request, params martini.Params, response http.ResponseWriter) {
		topic := params["_1"]

		body, err := ioutil.ReadAll(request.Body)
		if err != nil {
			panic("Unable to read body")
		}
		var valid_json interface{}
		err = json.Unmarshal(body, &valid_json)
		if err != nil {
			panic("Invalid JSON")
		}

		fmt.Println("Topic: " + topic)
		fmt.Println("Message: " + string(body))
		// Send message to storage
		// storage.Insert(topic, string(body))

		response.WriteHeader(http.StatusCreated)
	})

	m.Run()
}
开发者ID:yuemin-li,项目名称:gorse,代码行数:68,代码来源:server.go


示例19: main

func main() {
	flag.Parse()

	cfg, err := conf.ReadConfigFile(*configFile)
	if err != nil {
		log.Exitf("Failed to read configuration file: %v", err)
	}
	clusterName := cfgOpt(cfg, "cluster", "name")
	if clusterName == "" {
		log.Exit("Unable to get cluster name")
	}

	anycastEnabled := config.DefaultEngineConfig().AnycastEnabled
	if opt := cfgOpt(cfg, "cluster", "anycast_enabled"); opt != "" {
		if anycastEnabled, err = cfg.GetBool("cluster", "anycast_enabled"); err != nil {
			log.Exitf("Unable to parse cluster anycast_enabled: %v", err)
		}
	}
	clusterVIPv4, err := cfgIP(cfg, "cluster", "vip_ipv4")
	if err != nil {
		log.Exitf("Unable to get cluster vip_ipv4: %v", err)
	}
	clusterVIPv6, err := cfgIP(cfg, "cluster", "vip_ipv6")
	if err != nil {
		log.Exitf("Unable to get cluster vip_ipv6: %v", err)
	}
	nodeIPv4, err := cfgIP(cfg, "cluster", "node_ipv4")
	if err != nil {
		log.Exitf("Unable to get cluster node_ipv4: %v", err)
	}
	nodeIPv6, err := cfgIP(cfg, "cluster", "node_ipv6")
	if err != nil {
		log.Exitf("Unable to get cluster node_ipv6: %v", err)
	}
	peerIPv4, err := cfgIP(cfg, "cluster", "peer_ipv4")
	if err != nil {
		log.Exitf("Unable to get cluster peer_ipv4: %v", err)
	}
	peerIPv6, err := cfgIP(cfg, "cluster", "peer_ipv6")
	if err != nil {
		log.Exitf("Unable to get cluster peer_ipv6: %v", err)
	}

	// The default VRID may be overridden via the config file.
	vrid := config.DefaultEngineConfig().VRID
	if cfg.HasOption("cluster", "vrid") {
		id, err := cfg.GetInt("cluster", "vrid")
		if err != nil {
			log.Exitf("Unable to get VRID: %v", err)
		}
		if id < 1 || id > 255 {
			log.Exitf("Invalid VRID %d - must be between 1 and 255 inclusive", id)
		}
		vrid = uint8(id)
	}

	// Optional primary, secondary and tertiary configuration servers.
	configServers := make([]string, 0)
	for _, level := range []string{"primary", "secondary", "tertiary"} {
		if server := cfgOpt(cfg, "config_server", level); server != "" {
			configServers = append(configServers, server)
		}
	}
	if len(configServers) == 0 {
		configServers = config.DefaultEngineConfig().ConfigServers
	}

	nodeInterface := config.DefaultEngineConfig().NodeInterface
	if opt := cfgOpt(cfg, "interface", "node"); opt != "" {
		nodeInterface = opt
	}
	lbInterface := config.DefaultEngineConfig().LBInterface
	if opt := cfgOpt(cfg, "interface", "lb"); opt != "" {
		lbInterface = opt
	}

	// Additional anycast addresses.
	serviceAnycastIPv4 := config.DefaultEngineConfig().ServiceAnycastIPv4
	serviceAnycastIPv6 := config.DefaultEngineConfig().ServiceAnycastIPv6
	if cfg.HasSection("extra_service_anycast") {
		opts, err := cfg.GetOptions("extra_service_anycast")
		if err != nil {
			log.Exitf("Unable to get extra_serivce_anycast options: %v", err)
		}
		for _, opt := range opts {
			ip, err := cfgIP(cfg, "extra_service_anycast", opt)
			if err != nil {
				log.Exitf("Unable to get extra_service_anycast option %q: %v", opt, err)
			}
			if !seesaw.IsAnycast(ip) {
				log.Exitf("%q is not an anycast address", ip)
			}
			if ip.To4() != nil {
				serviceAnycastIPv4 = append(serviceAnycastIPv4, ip)
			} else {
				serviceAnycastIPv6 = append(serviceAnycastIPv6, ip)
			}
		}
	}

//.........这里部分代码省略.........
开发者ID:Cepave,项目名称:lvs-metrics,代码行数:101,代码来源:main.go


示例20: InitConfig

func InitConfig() {
	flag.Parse()

	// Parse data directory
	if Config.DataDir == "" {
		fmt.Println("  --data-dir option not specified. Please create a writable data directory and invoke deadci command with --data-dir=/path/to/data/dir")
		flag.CommandLine.PrintDefaults()
		os.Exit(2)
	}
	Config.DataDir = strings.TrimRight(Config.DataDir, "/ ")

	// Read the config file
	c, err := goconf.ReadConfigFile(Config.DataDir + "/deadci.ini")
	if err != nil {
		log.Fatal(err.Error() + ". Please ensure that your deadci.ini file is readable and in place at " + Config.DataDir + "/deadci.ini")
	}

	// Parse command
	cmd, err := c.GetString("", "command")
	if err != nil {
		log.Fatal(err)
	}
	cmd = strings.Trim(cmd, " ")
	if cmd == "" {
		log.Fatal("Missing command in deadci.ini. Please specify a command to run to build / test your repositories.")
	}
	Config.Command = strings.Split(cmd, " ")
	if len(Config.Command) == 0 {
		log.Fatal("Missing command in deadci.ini. Please specify a command to run to build / test your repositories.")
	}

	// Parse Port
	Config.Port, err = c.GetInt("", "port")
	if err != nil {
		log.Fatal(err)
	}

	// Parse Host
	Config.Host, err = c.GetString("", "host")
	if (err != nil && err.(goconf.GetError).Reason == goconf.OptionNotFound) || Config.Host == "" {
		Config.Host, err = os.Hostname()
		if err != nil {
			log.Fatal("Unable to determine hostname. Please specify a hostname in deadci.ini")
		}
	} else if err != nil {
		log.Fatal(err)
	}

	// Parse Temp Dir
	Config.TempDir, err = c.GetString("", "tempdir")
	if (err != nil && err.(goconf.GetError).Reason == goconf.OptionNotFound) || Config.TempDir == "" {
		Config.TempDir = os.TempDir()
	} else if err != nil {
		log.Fatal(err)
	}
	// Normalize tempdir string
	Config.TempDir = strings.TrimRight(Config.TempDir, "/")

	// Parse Github settings
	if c.HasSection("github") {
		Config.Github.Enabled, err = c.GetBool("github", "enabled")
		if err != nil && err.(goconf.GetError).Reason != goconf.OptionNotFound {
			log.Fatal(err)
		}
		if Config.Github.Enabled {
			Config.Github.Token, err = c.GetString("github", "token")
			if err != nil && err.(goconf.GetError).Reason != goconf.OptionNotFound {
				log.Fatal(err)
			}
			Config.Github.Secret, err = c.GetString("github", "secret")
			if err != nil && err.(goconf.GetError).Reason != goconf.OptionNotFound {
				log.Fatal(err)
			}
		}
	}

	// Parse clone style (git or https)
	Config.HttpsClone, err = c.GetBool("", "httpsclone")
	if err != nil && err.(goconf.GetError).Reason != goconf.OptionNotFound {
		log.Fatal(err)
	}

}
开发者ID:alxp,项目名称:deadci,代码行数:83,代码来源:config.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang goconf.ConfigFile类代码示例发布时间:2022-05-23
下一篇:
Golang lib.Broker类代码示例发布时间: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