Golang code-google-com-p-goconf-conf.ReadConfigFile类(方法)实例源码

下面列出了Golang code-google-com-p-goconf-conf.ReadConfigFile 类(方法)源码代码实例,从而了解它的用法。

作者:vil    项目:gerr   
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)
	}
}

作者:warrior172    项目:check-receive   
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))
}

作者:Khad    项目:obiwan-kanbanob   
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
}

作者:petemoor    项目:runli   
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
}

作者:sejohar    项目:hpfee   
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
}

作者:vichetu    项目:asin   
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
}

作者:lauborge    项目:gopistran   
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)
	}
}

作者:Dey    项目:go-newsag   
func ReadConfigFile(fname string) (c *ConfigFile, err error) {
	corg, err := conf.ReadConfigFile(fname)

	if err != nil {
		return nil, err
	}
	return &ConfigFile{*corg}, nil
}

作者:BrianI    项目:metric   
//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
}

作者:BrianI    项目:proden   
// 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
}

作者:AmandaCamero    项目:goba   
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
}

作者:v-s    项目:gotwi   
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)
}

作者:beer-roo    项目:tohv   
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"
}

作者:snarlysodboxe    项目:BTSyncInato   
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)
		}
	}
}

作者:philippwinkle    项目:uniqush-pus   
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
}

作者:ri    项目:gocm   
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
}

作者:NatTuc    项目:old-fogsyn   
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
}

作者:beer-roo    项目:tori   
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())
	}

}

作者:snarlysodboxe    项目:BTSyncInato   
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!")
	}
}

作者:AmandaCamero    项目:goba   
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
}


问题


面经


文章

微信
公众号

扫码关注公众号