本文整理汇总了Golang中github.com/alyu/configparser.Section.ValueOf方法的典型用法代码示例。如果您正苦于以下问题:Golang Section.ValueOf方法的具体用法?Golang Section.ValueOf怎么用?Golang Section.ValueOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/alyu/configparser.Section
的用法示例。
在下文中一共展示了Section.ValueOf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetConnection
// GetConnection - Return DB connection object based on config file.
func GetConnection(path string) abstract.Database {
var collection *mgo.Collection
conf, _ := configparser.Read(path)
checkError(conf, "Invalid configuration file")
driver_config, _ := conf.Section("nosql.db")
var db_config *configparser.Section
if strings.Contains(strings.ToLower(driver_config.ValueOf("name")), "mongo") {
db_config, _ = conf.Section("mongo")
driver_config.SetValueFor("name", "mongo")
} else if strings.Contains(strings.ToLower(driver_config.ValueOf("name")), "couch") {
db_config, _ = conf.Section("couch")
driver_config.SetValueFor("name", "couch")
}
switch strings.ToUpper(driver_config.ValueOf("name")) {
case "COUCH":
var db couch.Database
if db_config.ValueOf("user") == "" {
db, _ = couch.NewDatabase(db_config.ValueOf("ipaddress"), db_config.ValueOf("port"), db_config.ValueOf("dbname"))
} else {
db, _ = couch.NewDatabaseByURL("http://" + db_config.ValueOf("user") + ":" + db_config.ValueOf("password") + "@" + db_config.ValueOf("ipaddress") + ":" + db_config.ValueOf("port") + "/" + db_config.ValueOf("dbname"))
}
return abstract.Database(supported_db.CouchDb{db})
case "MONGO":
var mongoSession *mgo.Session
var err error
if db_config.ValueOf("user") == "" {
mongoSession, err = mgo.Dial(db_config.ValueOf("ipaddress") + ":" + db_config.ValueOf("port"))
} else {
mongoSession, err = mgo.Dial(db_config.ValueOf("user") + ":" + db_config.ValueOf("password") + "@" + db_config.ValueOf("ipaddress") + ":" + db_config.ValueOf("port") + "/" + db_config.ValueOf("dbname"))
}
checkError(mongoSession, err)
db := mongoSession.DB(db_config.ValueOf("dbname"))
collection = db.C(db_config.ValueOf("collectionname"))
return abstract.Database(supported_db.MongoDb{collection})
default:
panic("Supports only Couch or MongoDb")
}
return nil
}