本文整理汇总了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)
}
}
示例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))
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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"
}
示例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)
}
}
}
示例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
}