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

Golang conf.ReadConfigFile函数代码示例

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

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



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

示例1: init

func init() {
	var errors Errors
	basePath := os.Args[0]
	configPath = basePath[0:strings.LastIndex(basePath, "/")]
	if cfg, err := conf.ReadConfigFile(configPath + "/hooks.conf"); err == nil {
		if User, err = cfg.GetString("jira", "user"); err != nil {
			errors = append(errors, err)
		}
		if Pwd, err = cfg.GetString("jira", "password"); err != nil {
			errors = append(errors, err)
		}
		if JiraBaseUrl, err = cfg.GetString("jira", "baseUrl"); err != nil {
			errors = append(errors, err)
		}
		if Host, err = cfg.GetString("gerrit", "host"); err != nil {
			errors = append(errors, err)
		}
		if Port, err = cfg.GetString("gerrit", "port"); err != nil {
			errors = append(errors, err)
		}
		if len(errors) > 0 {
			panic(errors)
		}
	} else {
		panic(err)
	}
	var err error
	if LogFile, err = os.OpenFile(configPath+"/hooks.log", os.O_APPEND|os.O_WRONLY, 0600); err == nil {
		log.SetOutput(LogFile)
		log.SetFlags(log.LstdFlags | log.Lshortfile)
	} else {
		panic(err)
	}
}
开发者ID:vil1,项目名称:gerra,代码行数:34,代码来源:config.go


示例2: main

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	config_file := flag.String("conf", "default.conf", "Config file to use")
	flag.BoolVar(&DEBUG, "debug", false, "Enable debug output")
	flag.Parse()

	c, err := conf.ReadConfigFile(*config_file)
	if err != nil {
		log.Fatal("Error parsing config file: ", err)
	}

	LISTEN = getString(c, "", "listen")
	HTTP_HOST_HEADER = getString(c, "", "header")
	SPOOL_DIR = filepath.Clean(getString(c, "", "spool_dir"))
	PREFIX = getString(c, "", "file_prefix")
	PREFIX_TMP = getString(c, "", "tmpfile_prefix")

	if !isDir(SPOOL_DIR) {
		log.Fatalf("Spool directory %s does not exist or is not a directory", SPOOL_DIR)
	}

	// routing configuration
	http.HandleFunc("/", Handler)

	log.Print("Start listening on ", LISTEN, " spool=", SPOOL_DIR)
	log.Fatal(http.ListenAndServe(LISTEN, nil))
}
开发者ID:warrior1724,项目名称:check-receiver,代码行数:27,代码来源:main.go


示例3: readConf

func readConf(filename string) error {
	c, err := conf.ReadConfigFile(filename)
	if err != nil {
		return err
	}
	var err_psql, err_serv_port, err_log_file, err_tls_mode, err_verbose_mode error
	info_connect_bdd, err_psql = c.GetString("default", "db-uri")
	server_port, err_serv_port = c.GetInt("default", "server-port")
	log_file, err_log_file = c.GetString("default", "log-file")
	tls_mode, err_tls_mode = c.GetBool("default", "tls")
	verbose_mode, err_verbose_mode = c.GetBool("default", "verbose")

	// default value if not in the config file
	if err_psql != nil {
		info_connect_bdd = "postgres://kanban:[email protected]:5432/kanban"
	}
	if err_serv_port != nil {
		server_port = 9658
	}
	if err_log_file != nil {
		log_file = "kanban.log"
	}
	if err_tls_mode != nil {
		tls_mode = false
	}
	if err_verbose_mode != nil {
		verbose_mode = false
	}
	return nil
}
开发者ID:Khady,项目名称:obiwan-kanbanobi,代码行数:30,代码来源:main.go


示例4: NewContester

func NewContester(configFile string, gData *platform.GlobalData) (*Contester, error) {
	config, err := conf.ReadConfigFile(configFile)
	if err != nil {
		return nil, err
	}

	var result Contester

	result.InvokerId = getHostname()
	result.Env = getLocalEnvironment()
	result.ServerAddress, err = config.GetString("default", "server")
	if err != nil {
		return nil, err
	}
	result.Platform = PLATFORM_ID
	result.Disks = PLATFORM_DISKS
	result.ProgramFiles = PLATFORM_PFILES
	result.PathSeparator = string(os.PathSeparator)
	result.GData = gData

	result.Storage = storage.NewStorage()

	result.Sandboxes, err = configureSandboxes(config)
	if err != nil {
		return nil, err
	}

	return &result, nil
}
开发者ID:petemoore,项目名称:runlib,代码行数:29,代码来源:service.go


示例5: LoadConfig

func (this *Configurator) LoadConfig() *Config {
	var configFileName string
	flag.StringVar(&configFileName, "config", "hpfeed.conf", "path to config file")
	flag.Parse()

	config := Config{}
	configFile, err := conf.ReadConfigFile(configFileName)
	helper.HandleFatalError("loading config file failed (-config= forgotten):", err)

	config.Updateinterval, err = configFile.GetInt("", "updateinterval")
	helper.HandleFatalError("updateinterval", err)
	config.ListenPort, err = configFile.GetInt("", "listenPort")
	helper.HandleFatalError("listenPort", err)
	config.ListenPath, err = configFile.GetString("", "listenPath")
	helper.HandleFatalError("listenPath", err)
	config.Dbhost, err = configFile.GetString("", "dbhost")
	helper.HandleFatalError("dbhost", err)
	config.Dbport, err = configFile.GetString("", "dbport")
	helper.HandleFatalError("dbport", err)
	config.Dbname, err = configFile.GetString("", "dbname")
	helper.HandleFatalError("dbname", err)
	config.Dbuser, err = configFile.GetString("", "dbuser")
	helper.HandleFatalError("dbuser", err)
	config.Dbpassword, err = configFile.GetString("", "dbpassword")
	helper.HandleFatalError("dbpassword", err)
	config.ForumUser, err = configFile.GetString("", "forumUser")
	helper.HandleFatalError("forumUser", err)
	config.ForumPasswd, err = configFile.GetString("", "forumPasswd")
	helper.HandleFatalError("forumPasswd", err)
	return &config
}
开发者ID:sejoharp,项目名称:hpfeed,代码行数:31,代码来源:configurator.go


示例6: getSocketFromArgs

func getSocketFromArgs(args []string) (string, error) {
	const config_usage = "Config File to use"
	userHomeDir := "~"

	u, err := user.Current()
	if err == nil {
		userHomeDir = u.HomeDir
	}

	flags := flag.NewFlagSet("stop", flag.ExitOnError)
	flags.StringVar(&globals.configFileName, "config", path.Join(userHomeDir, ".asink", "config"), config_usage)
	flags.StringVar(&globals.configFileName, "c", path.Join(userHomeDir, ".asink", "config"), config_usage+" (shorthand)")
	flags.Parse(args)

	config, err := conf.ReadConfigFile(globals.configFileName)
	if err != nil {
		return "", err
	}

	rpcSock, err := config.GetString("local", "socket")
	if err != nil {
		return "", errors.New("Error reading local.socket from config file at " + globals.configFileName)
	}

	return rpcSock, nil
}
开发者ID:vichetuc,项目名称:asink,代码行数:26,代码来源:client.go


示例7: init

func init() {
	var err error
	// reading config file

	c, err := conf.ReadConfigFile("Gopfile")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	user, err = c.GetString("", "username")
	pass, err = c.GetString("", "password")
	hostname, err = c.GetString("", "hostname")
	repository, err = c.GetString("", "repository")
	path, err = c.GetString("", "path")
	releases = path + "/releases"
	shared = path + "/shared"
	utils = path + "/utils"

	keep_releases, err = c.GetString("", "keep_releases")

	//just log whichever we get; let the user re-run the program to see all errors... for now
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
}
开发者ID:lauborges,项目名称:gopistrano,代码行数:27,代码来源:gopistrano.go


示例8: ReadConfigFile

func ReadConfigFile(fname string) (c *ConfigFile, err error) {
	corg, err := conf.ReadConfigFile(fname)

	if err != nil {
		return nil, err
	}
	return &ConfigFile{*corg}, nil
}
开发者ID:DeyV,项目名称:go-newsagg,代码行数:8,代码来源:conf.go


示例9: CheckAll

//ranges through config file and checks all expressions.
// prints result messages to stdout
func (c *checker) CheckAll() ([]CheckResult, error) {
	result := []CheckResult{}
	cnf, err := conf.ReadConfigFile(c.configFile)
	if err != nil {
		return nil, err
	}
	for _, section := range cnf.GetSections() {
		if section == "default" {
			continue
		}
		expr, _ := cnf.GetString(section, "expr")
		_, r, err := types.Eval(expr, c.pkg, c.sc)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			continue
		}
		cr := &CheckResult{
			Name: section,
		}
		var m string
		if exact.BoolVal(r) {
			m, err = cnf.GetString(section, "true")
			if err != nil {
				continue
			}
		} else {
			m, err = cnf.GetString(section, "false")
			if err != nil {
				continue
			}
		}
		val, err := cnf.GetString(section, "val")
		if err == nil {
			t, v, err := types.Eval(val, c.pkg, c.sc)
			if err == nil {
				if types.Identical(t, types.Typ[types.UntypedFloat]) || types.Identical(t, types.Typ[types.Float64]) {
					x, _ := exact.Float64Val(v)
					cr.Value = x
				}
			}
		}
		owner, err := cnf.GetString(section, "owner")
		if err == nil {
			cr.Owner = owner
		} else {
			cr.Owner = "unknown"
		}

		_, msg, err := types.Eval(m, c.pkg, c.sc)
		if err != nil {
			cr.Message = m
		} else {
			cr.Message = exact.StringVal(msg)
		}
		result = append(result, *cr)
	}
	return result, nil
}
开发者ID:BrianIp,项目名称:metrics,代码行数:60,代码来源:check_impl.go


示例10: New

// create connection to mysql database here
// when an error is encountered, still return database so that the logger may be used
func New(user, password, config string) (MysqlDB, error) {

	dsn := map[string]string{"dbname": "information_schema"}
	creds := map[string]string{"root": "/root/.my.cnf", "nrpe": "/etc/my_nrpe.cnf"}

	database := &mysqlDB{
		Logger: log.New(os.Stderr, "LOG: ", log.Lshortfile),
	}

	if user == "" {
		user = DEFAULT_MYSQL_USER
		dsn["user"] = DEFAULT_MYSQL_USER
	} else {
		dsn["user"] = user
	}
	if password != "" {
		dsn["password"] = password
	}
	//	socket_file := "/var/lib/mysql/mysql.sock"
	//	if _, err := os.Stat(socket_file); err == nil {
	//		dsn["unix_socket"] = socket_file
	//	}

	//Parse ini file to get password
	ini_file := creds[user]
	if config != "" {
		ini_file = config
	}
	_, err := os.Stat(ini_file)
	if err != nil {
		fmt.Println(err)
		return database, errors.New("'" + ini_file + "' does not exist")
	}
	// read ini file to get password
	c, err := conf.ReadConfigFile(ini_file)
	if err != nil {
		return database, err
	}
	pw, err := c.GetString("client", "password")
	dsn["password"] = strings.Trim(pw, " \"")
	database.dsnString = makeDsn(dsn)

	//make connection to db
	db, err := sql.Open("mysql", database.dsnString)
	if err != nil {
		return database, err
	}
	database.db = db

	//ping db to verify connection
	err = database.db.Ping()
	if err != nil {
		return database, err
	}
	fmt.Println("connected to " + user + " @ " + dsn["dbname"])
	return database, nil
}
开发者ID:BrianIp,项目名称:prodeng,代码行数:59,代码来源:mysqltools_impl.go


示例11: NewShellSource

func NewShellSource(sess *dbus.Connection, x *xdg.XDG) *ShellSource {
	ss := &ShellSource{
		sess_conn: sess,
		Xdg:       x,
	}
	for _, dir := range []string{
		"/usr/share/gnome-shell/search-providers",
		"/usr/local/share/gnoem-shell/search-providers",
	} {

		srcs, err := ioutil.ReadDir(dir)
		//utils.FailMeMaybe(err)
		if err != nil {
			continue
		}
		for _, file := range srcs {
			cfg, err := conf.ReadConfigFile(dir + "/" + file.Name())
			utils.FailMeMaybe(err)

			SSP := "Shell Search Provider"

			objPath, err := cfg.GetString(SSP, "ObjectPath")
			if err != nil {
				continue
			}

			busName, err := cfg.GetString(SSP, "BusName")
			if err != nil {
				continue
			}

			var name, icon string

			name, err = cfg.GetString(SSP, "Name")
			if err != nil {
				did, err := cfg.GetString(SSP, "DesktopId")
				if err == nil {
					name, icon = getName(did)
				}
			}

			if icon == "" {
				if tmp, err := cfg.GetString(SSP, "Icon"); err == nil {
					icon = tmp
				}
			}

			searcher := gs_search.New(sess.Object(busName, dbus.ObjectPath(objPath)))
			searcher.Name = name
			searcher.Icon = icon

			ss.searchers = append(ss.searchers, searcher)
		}
	}

	return ss
}
开发者ID:AmandaCameron,项目名称:gobar,代码行数:57,代码来源:ct_shell_search.go


示例12: main

func main() {
	flag.Parse()
	var err error
	mainConf, err = conf.ReadConfigFile(confFileName)

	if err != nil {
		log.Panicf("Error reading config file: err %s", err)
	}
	httpServe.Run(mainConf)
}
开发者ID:v-sh,项目名称:gotwit,代码行数:10,代码来源:front.go


示例13: initHost

func initHost() string {
	c, err := conf.ReadConfigFile("./tohva-test.conf")
	if err == nil {
		h, err := c.GetString("database", "host")
		if err == nil {
			return h
		}
	}
	return "localhost"
}
开发者ID:beer-root,项目名称:tohva,代码行数:10,代码来源:test_conf.go


示例14: readSlashCreateConfig

func readSlashCreateConfig() {
	if _, err := os.Stat(*configFilePath); os.IsNotExist(err) {
		config.WriteConfigFile(*configFilePath, 0600, configHeader)
	} else {
		config, err = conf.ReadConfigFile(*configFilePath)
		if err != nil {
			log.Fatal("Error with ReadConfigFile:", err)
		}
	}
}
开发者ID:snarlysodboxer,项目名称:BTSyncInator,代码行数:10,代码来源:config.go


示例15: OpenConfig

func OpenConfig(filename string) (c *conf.ConfigFile, err error) {
	if filename == "" {
		filename = defaultConfigFilePath
	}
	c, err = conf.ReadConfigFile(filename)
	if err != nil {
		return nil, err
	}
	return
}
开发者ID:philippwinkler,项目名称:uniqush-push,代码行数:10,代码来源:configparser.go


示例16: main

func main() {
	c, err := conf.ReadConfigFile("something.config")
	if err != nil {
		log.Panic("cannot open config file: ", err)
	}
	log.Print(c.GetString("default", "host"))        // return something.com
	log.Print(c.GetInt("default", "port"))           // return 443
	log.Print(c.GetBool("default", "active"))        // return true
	log.Print(c.GetBool("default", "compression"))   // return false
	log.Print(c.GetBool("default", "compression"))   // returns false
	log.Print(c.GetBool("service-1", "compression")) // returns true
	log.Print(c.GetBool("service-2", "compression")) // returns GetError
}
开发者ID:rif,项目名称:gocmd,代码行数:13,代码来源:conf.go


示例17: Load

func Load() *conf.ConfigFile {
	if config != nil {
		return config
	}

	path := ConfFile()

	config1, err := conf.ReadConfigFile(path)
	if err != nil {
		log.Println("Error reading config; writing out default")

		os.MkdirAll(ConfDir(), 0700)

		file, err := os.OpenFile(path,
			os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
		if err != nil {
			log.Fatalln("Could not create config file:", err)
		}

		_, err = file.WriteString(defaultConfig)
		if err != nil {
			log.Fatalln("Write error:", err)
		}

		err = file.Close()
		if err != nil {
			log.Fatalln("Error on close:", err)
		}

		config1, err = conf.ReadConfigFile(path)
		if err != nil {
			log.Fatalln("Could not read new default config file:", err)
		}
	}

	config = config1
	return config
}
开发者ID:NatTuck,项目名称:old-fogsync,代码行数:38,代码来源:settings.go


示例18: init

func init() {

	// command line options
	var confFile string
	flag.StringVar(&confFile, "config", "/etc/toris/toris.conf", "The configuration file")

	flag.BoolVar(&ShowModules, "module-list", false, "Print the list of loaded modules and exits")

	flag.Parse()

	// read the configuration file
	config, err := conf.ReadConfigFile(confFile)
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	// initializes the database connection
	dbHost, _ := config.GetString("database", "host")
	dbPort, _ := config.GetInt("database", "port")
	dbName, _ := config.GetString("database", "name")
	adminName, _ := config.GetString("database", "admin_name")
	adminPwd, _ := config.GetString("database", "admin_password")

	couch := tohva.CreateCouchClient(dbHost, dbPort)

	// the secret token for secure cookies
	secretToken, _ := config.GetString("sessions", "secret")

	Context = Toris{
		map[string]InstalledModule{},
		config,
		&couch,
		dbName,
		adminName,
		adminPwd,
		sessions.NewCookieStore([]byte(secretToken))}

	// start all the modules
	for _, m := range Context.modules {
		log.Println("Starting module " + m.module.Name())
	}

}
开发者ID:beer-root,项目名称:toris,代码行数:44,代码来源:core.go


示例19: configDeleteHandler

func configDeleteHandler(writer http.ResponseWriter, request *http.Request) {
	readSlashCreateConfig()
	if config.RemoveSection(request.FormValue("DeleteName")) {
		err := config.WriteConfigFile(*configFilePath, 0600, configHeader)
		if err != nil {
			log.Fatalf("Error with WriteConfigFile: %s", err)
		}
		dmns, err := conf.ReadConfigFile(*configFilePath)
		if err != nil {
			log.Fatalf("Error with ReadConfigFile: %s", err)
		} else {
			config = dmns
			setupDaemonsFromConfig()
			http.Redirect(writer, request, "/config", http.StatusFound)
		}
	} else {
		log.Fatal(writer, "Error with RemoveSection!")
	}
}
开发者ID:snarlysodboxer,项目名称:BTSyncInator,代码行数:19,代码来源:config.go


示例20: LoadApplication

func (xdg *XDG) LoadApplication(path string) (*Application, error) {
	cfg, err := conf.ReadConfigFile(path)
	if err != nil {
		return nil, err
	}

	app := &Application{}

	DE := "Desktop Entry"

	app.Exec, err = cfg.GetRawString(DE, "Exec")
	if err != nil {
		return nil, err
	}

	app.Icon, err = cfg.GetRawString(DE, "Icon")
	if err != nil {
		app.Icon = ""
	}

	app.Name, err = cfg.GetRawString(DE, "Name")
	if err != nil {
		return nil, err
	}

	app.Type, err = cfg.GetRawString(DE, "Type")
	if err != nil {
		return nil, err
	}

	app.NoDisplay, err = cfg.GetBool(DE, "NoDisplay")
	if err != nil {
		app.NoDisplay = false
	}

	app.cfg = cfg
	app.xdg = xdg

	return app, nil
}
开发者ID:AmandaCameron,项目名称:gobar,代码行数:40,代码来源:apps.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang conf.ConfigFile类代码示例发布时间:2022-05-24
下一篇:
Golang jwt.NewToken函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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