當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。