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


Golang config.ReadDefault函数代码示例

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


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

示例1: ProcessCommand

func (cp *ConfigPlugin) ProcessCommand(cmd *IRCCommand) {
	var err error
	switch cmd.Command {
	case "version":
		cp.ic.Reply(cmd, cp.ic.GetStringOption("Info", "version"))
	case "source":
		cp.ic.Reply(cmd, cp.ic.GetStringOption("Info", "source"))
	case "writeconfig":
		cp.Lock()
		err = cp.Conf.WriteFile(cp.filename, 0644, "IRC Bot Config")
		if err != nil {
			cp.ic.Reply(cmd, "Error writing config: "+err.Error())
		}
		cp.Conf, err = config.ReadDefault(cp.filename)
		if err != nil {
			cp.ic.Reply(cmd, "Error loading config: "+err.Error())
		}
		cp.Unlock()
		cp.ic.Reply(cmd, "Successfully flushed cached config entries")
	case "loadconfig":
		cp.Lock()
		cp.Conf, err = config.ReadDefault(cp.filename)
		if err != nil {
			cp.ic.Reply(cmd, "Error loading config: "+err.Error())
		}
		cp.Unlock()
		cp.ic.Reply(cmd, "Successfully loaded config entries")
	}
}
开发者ID:0x17de,项目名称:MettBot,代码行数:29,代码来源:conf.go

示例2: NewConfigPlugin

func NewConfigPlugin(filename string) *ConfigPlugin {
	c, ok := config.ReadDefault(filename)
	if ok != nil {
		c = config.NewDefault()
		c.AddSection("Server")
		c.AddOption("Server", "host", "dpaulus.dyndns.org:6667")
		c.AddOption("Server", "nick", "testbot")
		c.AddOption("Server", "ident", "ident")
		c.AddOption("Server", "realname", "TestBot Client")
		c.AddOption("Server", "trigger", ".")
		c.AddSection("Auth")
		c.AddSection("Info")
		c.WriteFile(filename, 0644, "IRC Bot default config file")
		log.Println("Note: A new default configuration file has been generated in " + filename + ". Please edit it to suit your needs and restart the bot then")
		os.Exit(1)
	}
	for _, x := range []string{"host", "nick", "ident", "realname"} {
		_, err := c.String("Server", x)
		if err != nil {
			log.Fatal("Error while parsing config: " + err.Error())
		}
	}
	trigger, err := c.String("Server", "trigger")
	if err != nil {
		log.Fatal(err)
	}
	if utf8.RuneCountInString(trigger) != 1 {
		log.Fatal("Trigger must be exactly one unicode rune long")
	}
	return &ConfigPlugin{filename: filename, Conf: c}
}
开发者ID:0x17de,项目名称:MettBot,代码行数:31,代码来源:conf.go

示例3: ReadIniFile

func ReadIniFile(inifile string) error {
	conf, err := config.ReadDefault(inifile)
	if err != nil {
		return fmt.Errorf("Read %v error. %v", inifile, err.Error())
	}

	Addr, _ = conf.String("service", "addr")
	NumCpu, _ = conf.Int("service", "num_cpu")
	AcceptTimeout, _ = conf.Int("service", "accept_timeout")
	ReadTimeout, _ = conf.Int("service", "read_timeout")
	WriteTimeout, _ = conf.Int("service", "write_timeout")

	UuidDB, _ = conf.String("data", "uuid_db")
	OfflineMsgidsDB, _ = conf.String("data", "offline_msgids_db")
	IdToMsgDB, _ = conf.String("data", "id_to_msg_db")
	TimedUpdateDB, _ = conf.Int("data", "timed_update_db")

	LogFile, _ = conf.String("debug", "logfile")

	EmailServerAddr, _ = conf.String("email", "email_server_addr")
	EmailServerPort, _ = conf.String("email", "email_server_port")
	EmailAccount, _ = conf.String("email", "email_account")
	EmailPassword, _ = conf.String("email", "email_password")
	EmailToList, _ = conf.String("email", "email_tolist")
	EmailDuration, _ = conf.Int("email", "email_duration")

	return nil
}
开发者ID:jackwanger,项目名称:chatserver,代码行数:28,代码来源:config.go

示例4: init

func init() {
	flagset := flag.NewFlagSet("config", flag.ContinueOnError)
	flagset.StringVar(&configFile, "config", "", "Config File")
	flagset.StringVar(&uuid, "uuid", "", "uuid")

	args, _ := SplitFlagsetFromArgs(flagset, os.Args[1:])
	flagset.Parse(args)

	// Ensure we have a UUID
	if uuid == "" {
		uuid = NewUUID()
	}

	if configFile == "" {
		for _, f := range defaultConfigFiles {
			if _, err := os.Stat(f); err == nil {
				configFile = f
				break
			}
		}
	}

	if configFile == "" {
		log.Println(log.ERROR, "Failed to find config file")
		conf = config.NewDefault()
		return
	}

	if _, err := os.Stat(configFile); os.IsNotExist(err) {
		log.Println(log.ERROR, "Config file does not exist", err)
		conf = config.NewDefault()
		return
	}

	var err error
	if conf, err = config.ReadDefault(configFile); err != nil {
		conf = config.NewDefault()
		log.Fatal(err)
	}

	// Set default log level from config, this can be overriden at the service level when the service is created
	if l, err := conf.RawStringDefault("log.level"); err == nil {
		log.SetLogLevel(log.LevelFromString(l))
	}

	// Set default log level from config, this can be overriden at the service level when the service is created
	if lh, err := conf.RawStringDefault("log.sysloghost"); err == nil {
		log.SetSyslogHost(lh)
	}

	// Set syslog port
	if i, err := conf.Int("DEFAULT", "log.syslogport"); err == nil {
		log.SetSyslogPort(i)
	}

	// Set GOMAXPROCS
	if i, err := conf.Int("DEFAULT", "runtime.gomaxprocs"); err == nil {
		runtime.GOMAXPROCS(i)
	}
}
开发者ID:bubble66,项目名称:skynet,代码行数:60,代码来源:config.go

示例5: LoginHandler

func LoginHandler(w http.ResponseWriter, r *http.Request, session sessions.Session, log *log.Logger) string {
	c, err := config.ReadDefault("users.cfg")

	if err != nil {
		return "Can't login. Problems reading user and password."
	}

	username := r.FormValue("username")
	password := r.FormValue("password")

	allowedUsername, _ := c.RawStringDefault("user")
	allowedPassword, _ := c.RawStringDefault("password")

	if username == allowedUsername && password == allowedPassword {

		log.Print("User WAS logged in.")

		session.Set("username", username)
		session.Set("password", password)
		http.Redirect(w, r, "/home", http.StatusFound)
		return "OK"
	}

	log.Print("User wasn't logged in. User " + username + " and password " + password)

	http.Redirect(w, r, "/login", http.StatusFound)
	return "Username or password incorrect"
}
开发者ID:patrickdappollonio,项目名称:projects,代码行数:28,代码来源:handlers.go

示例6: loadConfig

func loadConfig() {
	var err error
	Config, err = config.ReadDefault("app.conf")
	if err != nil {
		log.Fatalf("Error loading config. ERR: %+v", err)
	}
}
开发者ID:arvindram03,项目名称:asynch-workers,代码行数:7,代码来源:main.go

示例7: sendMail

//发送邮件
func sendMail(subject, content string, tos []string) {
	fmt.Println("发送邮件")
	mailer := &mail.Mailer{}
	from := ""
	if mailer.UserName == "" {
		//basePath := revel.BasePath
		//c, _ := config.ReadDefault(basePath + "/conf/qishare.conf")
		c, _ := config.ReadDefault(revel.BasePath + "/conf/qishare.conf")
		/*mailer.UserName, _ = c.String("smtp", "smtp.username")
		mailer.Password, _ = c.String("smtp", "smtp.password")
		from, _ = c.String("smtp", "smtp.from")
		mailer.Server, _ = c.String("smtp", "smtp.server")
		mailer.Port, _ = c.Int("smtp", "smtp.port")*/
		fmt.Println("BasePath" + revel.BasePath)
		fmt.Println(c)
		mailer.UserName = "[email protected]"
		mailer.Password = "7442008"
		from = "[email protected]"
		mailer.Server = "smtp.sina.com"
		mailer.Port = 25
	}
	//mailer := &mail.Mailer{Server: "smtp.sina.com", Port: 25, UserName: "[email protected]", Password: "7442008"}
	message := &mail.Message{From: from, To: tos, Subject: subject, PlainBody: bytes.NewBufferString(content)}

	err := mailer.SendMessage(message)
	if err != nil {
		fmt.Println(err)
	}
}
开发者ID:river-lee,项目名称:qishare,代码行数:30,代码来源:util.go

示例8: main

func main() {

	//db access for releases
	db, err := sql.Open("sqlite3", "./release.db")
	if err != nil {
		panic(err.Error())
	}
	reldb := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}
	reldb.AddTableWithName(town.Release{}, "release").SetKeys(false, "Checksum").ColMap("Checksum").SetUnique(true).SetNotNull(true)
	reldb.CreateTablesIfNotExists()

	//db for logs
	//different database cause of locks with high log frequency
	dblog, err := sql.Open("sqlite3", "./logs.db")
	dbmap := &gorp.DbMap{Db: dblog, Dialect: gorp.SqliteDialect{}}
	dbmap.AddTableWithName(mydb.Log{}, "log").SetKeys(true, "Uid")
	dbmap.CreateTablesIfNotExists()
	logdb := mydb.DBLog{DB: dbmap}
	if err != nil {
		panic(err.Error())
	}

	logging.SetOutput(logdb)

	//read config file
	c, _ := config.ReadDefault("default.ini")

	//webserver
	serv := &webserv.Server{Config: c, RelDB: reldb, LogDB: dbmap}
	serv.Init()

}
开发者ID:Bootz,项目名称:nzbcrawler,代码行数:32,代码来源:main.go

示例9: register

func register(ctx *cli.Context) {

	fn := path.Join(ctx.String("directory"), ".gomr")

	newTags := strings.Split(ctx.String("tag"), ",")

	if ctx.Bool("append") {
		if _, err := os.Stat(fn); err == nil {
			cfg, _ := config.ReadDefault(".gomr")
			curTags, _ := cfg.String("gomr", "tags")

			for _, tag := range strings.Split(curTags, ",") {
				newTags = AppendIfMissing(newTags, tag)
			}
		} else {
			err := "append used, existing file not found."
			fmt.Fprintf(os.Stderr, "error: %v\n", err)
			os.Exit(1)
		}
	}

	outTags := strings.Join(newTags, ",")

	outCfg := config.NewDefault()
	outCfg.AddSection("gomr")
	outCfg.AddOption("gomr", "tags", outTags)
	outCfg.WriteFile(fn, 0644, "gomr configuration file")

	return
}
开发者ID:FranklinChen,项目名称:python-ruby-golang,代码行数:30,代码来源:register.go

示例10: sendMail

func sendMail(subject, content string, tos []string) error {
	message := `From: Revel社区
To: ` + strings.Join(tos, ",") + `
Subject: ` + subject + `
Content-Type: text/html;charset=UTF-8

` + content
	if Smtp.username == "" {
		path, _ := filepath.Abs("")
		c, _ := config.ReadDefault(fmt.Sprintf("%s/src/revelapp/conf/my.conf", path))

		Smtp.username, _ = c.String("smtp", "smtp.username")
		Smtp.password, _ = c.String("smtp", "smtp.password")
		Smtp.address, _ = c.String("smtp", "smtp.address")
		Smtp.from, _ = c.String("smtp", "smtp.from")
		Smtp.host, _ = c.String("smtp", "smtp.host")
	}

	auth := smtp.PlainAuth("", Smtp.username, Smtp.password, Smtp.host)
	err := smtp.SendMail(Smtp.address, auth, Smtp.from, tos, []byte(message))
	if err != nil {
		fmt.Println(err)
		return err
	}

	return nil
}
开发者ID:jsli,项目名称:gorevel,代码行数:27,代码来源:comm.go

示例11: Init

func Init() {
	c, err := config.ReadDefault(revel.BasePath + "/conf/my.conf")
	driver, _ := c.String("database", "db.driver")
	dbname, _ := c.String("database", "db.dbname")
	user, _ := c.String("database", "db.user")
	password, _ := c.String("database", "db.password")
	host, _ := c.String("database", "db.host")

	params := fmt.Sprintf("%s:%[email protected](%s)/%s?charset=utf8&parseTime=true", user, password, host, dbname)
	Engine, err = xorm.NewEngine(driver, params)
	if err != nil {
		panic(err)
	}
	Engine.ShowSQL = revel.DevMode
	err = Engine.Sync(
		new(User),
		new(Category),
		new(Movie),
		// new(Reply),
		// new(Permissions),
	)

	if err != nil {
		panic(err)
	}
}
开发者ID:dalinhuang,项目名称:1tv8,代码行数:26,代码来源:init.go

示例12: loadConfig

func loadConfig() (err error) {
	Config, err = config.ReadDefault("../app.conf")
	if err != nil {
		log.Fatalf("Failed to read configs. ERR: %+v", err)
	}
	return err
}
开发者ID:arvindram03,项目名称:asynch-workers,代码行数:7,代码来源:log_aggregator.go

示例13: ReadIniFile

func ReadIniFile(inifile string) error {
	conf, err := config.ReadDefault(inifile)
	if err != nil {
		return fmt.Errorf("Read %v error. %v", inifile, err.Error())
	}

	Addr, _ = conf.String("service", "addr")
	NumCpu, _ = conf.Int("service", "num_cpu")
	AcceptTimeout, _ = conf.Int("service", "accept_timeout")
	ReadTimeout, _ = conf.Int("service", "read_timeout")
	WriteTimeout, _ = conf.Int("service", "write_timeout")

	C2COfflinemsgRedisAddr, _ = conf.String("redisdb", "c2c_offlinemsg_redisAddr")
	C2COfflinemsgRedisKeyExpireDay, _ = conf.String("redisdb", "c2c_offlinemsg_redisKeyExpireDay")

	LogFile, _ = conf.String("debug", "logfile")

	EmailServerAddr, _ = conf.String("email", "email_server_addr")
	EmailServerPort, _ = conf.String("email", "email_server_port")
	EmailAccount, _ = conf.String("email", "email_account")
	EmailPassword, _ = conf.String("email", "email_password")
	EmailToList, _ = conf.String("email", "email_tolist")
	EmailDuration, _ = conf.Int("email", "email_duration")

	return nil
}
开发者ID:neutony,项目名称:chatserver,代码行数:26,代码来源:config.go

示例14: SetDB

//设置数据库
func SetDB() {
	path, _ := filepath.Abs("")
	c, _ := config.ReadDefault(fmt.Sprintf("%s/admin/conf/databases.conf", path))

	driver, _ := c.String("database", "db.driver")
	dbname, _ := c.String("database", "db.dbname")
	user, _ := c.String("database", "db.user")
	password, _ := c.String("database", "db.password")
	host, _ := c.String("database", "db.host")
	//prefix, _ := c.String("database", "db.prefix")

	//数据库链接
	var err error
	Engine, err = xorm.NewEngine(driver, fmt.Sprintf("%s:%[email protected](%s)/%s?charset=utf8", user, password, host, dbname))
	if err != nil {
		revel.WARN.Printf("错误: %v", err)
	}

	//缓存方式是存放到内存中,缓存struct的记录数为1000条
	//cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
	//Engine.SetDefaultCacher(cacher)

	//控制台打印SQL语句
	//Engine.ShowSQL = true

	//控制台打印调试信息
	//Engine.ShowDebug = true

	//控制台打印错误信息
	//Engine.ShowErr = true

	//控制台打印警告信息
	//Engine.ShowWarn = true
}
开发者ID:qmdx,项目名称:GoCMS,代码行数:35,代码来源:init.go

示例15: ParseConfig

func ParseConfig(configPath string) (ci ConfigInfo, err error) {
	conf, err := config.ReadDefault(configPath)
	if err != nil {
		return
	}
	businessList, _ := conf.String("mode", "BusinessList")
	masterConf, _ := conf.String("master", "MasterConf")
	masterRestartScript, _ := conf.String("master", "MasterRestartScript")

	copyMethod, _ := conf.Int("slave", "CopyMethod")
	slaveServerIp, _ := conf.String("slave", "SlaveServerIp")
	slaveServerSSHPort, _ := conf.Int("slave", "SlaveServerSSHPort")
	slaveRemoteUser, _ := conf.String("slave", "SlaveRemoteUser")
	slaveRemotePasswd, _ := conf.String("slave", "SlaveRemotePasswd")
	sshCommandPath, _ := conf.String("slave", "SSHCommandPath")
	scpCommandPath, _ := conf.String("slave", "ScpCommandPath")

	slaveConf, _ := conf.String("slave", "SlaveConf")
	slaveRestartScript, _ := conf.String("slave", "SlaveRestartScript")

	storeScheme, _ := conf.Int("store", "StoreScheme")

	dbDriverName, _ := conf.String("store", "DBDriverName")
	dbDataSourceName, _ := conf.String("store", "DBDataSourceName")

	fileToReplaceDB, _ := conf.String("store", "FileToReplaceDB")

	masterStatsPage, _ := conf.String("stats", "MasterStatsPage")
	slaveStatsPage, _ := conf.String("stats", "SlaveStatsPage")

	vip, _ := conf.String("others", "Vip")

	newHAProxyConfPath, _ := conf.String("others", "NewHAProxyConfPath")

	ci = ConfigInfo{
		BusinessList:        businessList,
		MasterConf:          masterConf,
		MasterRestartScript: masterRestartScript,
		CopyMethod:          copyMethod,
		SlaveServerIp:       slaveServerIp,
		SlaveServerSSHPort:  slaveServerSSHPort,
		SlaveRemoteUser:     slaveRemoteUser,
		SlaveRemotePasswd:   slaveRemotePasswd,
		SSHCommandPath:      sshCommandPath,
		ScpCommandPath:      scpCommandPath,
		SlaveConf:           slaveConf,
		SlaveRestartScript:  slaveRestartScript,
		StoreScheme:         storeScheme,
		DBDriverName:        dbDriverName,
		DBDataSourceName:    dbDataSourceName,
		FileToReplaceDB:     fileToReplaceDB,
		MasterStatsPage:     masterStatsPage,
		SlaveStatsPage:      slaveStatsPage,
		Vip:                 vip,
		NewHAProxyConfPath:  newHAProxyConfPath,
	}
	err = CheckConfig(ci)
	return
}
开发者ID:yinwer81,项目名称:haproxyconsole,代码行数:59,代码来源:config.go


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