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


Golang conf.ReadConfigFile函数代码示例

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


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


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