本文整理汇总了Golang中github.com/alyu/configparser.Read函数的典型用法代码示例。如果您正苦于以下问题:Golang Read函数的具体用法?Golang Read怎么用?Golang Read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Init
// Init Loads a INI file onto memory, first try to liad the config file from
// the etc/ directory on the current path, and if the file can't be found, try
// to load it from the /etc/ directory
// The name of the file to be used has to be the specified "appName_env.ini"
func Init(appName, env string) (err error) {
// Trying to read the config file form the /etc directory on a first
// instance
if cfg, err = configparser.Read(fmt.Sprintf("etc/%s_%s.ini", appName, env)); err != nil {
cfg, err = configparser.Read(fmt.Sprintf("/etc/%s_%s.ini", appName, env))
}
return
}
示例2: TestReadConfig
func TestReadConfig(t *testing.T) {
config, err := configparser.Read("fastforward.conf")
if err != nil {
t.Error(err)
}
log.Printf("full configuration:\n%s", config)
}
示例3: main
func main() {
// Read the configuration from hook.conf
config, err := configparser.Read("hook.conf")
if err != nil {
log.Fatalln(err)
}
section, err := config.Section("host")
if err != nil {
log.Fatalln(err)
}
urlStr := section.ValueOf("url")
// Create a JSON node tree
rootNode := jpath.NewNode()
rootNode.Set("text", `---
##### Build Break - Project X - December 12, 2015 - 15:32 GMT +0
| Component | Tests Run | Tests Failed |
|:-----------|:------------|:-----------------------------------------------|
| Server | 948 | :ghost: 0 |
| Web Client | 123 | :warning: [2 (see details)](http://linktologs) |
| iOS Client | 78 | :poop: [3 (see details)](http://linktologs) |
---`)
rootNode.Set("username", "HookBot9000")
// Send the message to the Mattermost host
if status, err := mattersend.Send(urlStr, rootNode); err != nil || status != "200 OK" {
log.Fatalln("FAIL", err, status)
}
fmt.Println("SUCCESS")
}
示例4: main
func main() {
flag.Usage = usage
debug := flag.Bool("d", false, "debug")
conffile := flag.String("c", "config.ini", "config file")
flag.Parse()
if *debug {
xmpp.Debug = true
}
config, err := configparser.Read(*conffile)
if err != nil {
log.Fatal(*conffile, err)
}
section, err := config.Section("global")
if err != nil {
log.Fatal(err)
}
jid := xmpp.JID(section.ValueOf("jid"))
pass := section.ValueOf("pass")
status := make(chan xmpp.Status, 10)
go func() {
for s := range status {
log.Printf("connection status %s", statuses[s])
}
}()
jid = xmpp.JID(fmt.Sprintf("%s/%s", jid.Bare(), "bot"))
c, err := xmpp.NewClient(&jid, pass, tls.Config{InsecureSkipVerify: true}, nil, xmpp.Presence{}, status)
if err != nil {
log.Fatalf("NewClient(%v): %v", jid, err)
}
defer c.Close()
for {
select {
case s := <-status:
log.Printf("connection status %s", statuses[s])
if s.Fatal() {
return
}
case st, ok := <-c.Recv:
if !ok {
return
}
if m, ok := st.(*xmpp.Message); ok {
log.Printf("msg from %s", m.From.Bare())
process(m, c)
}
if p, ok := st.(*xmpp.Presence); ok {
log.Printf("presence from %s", p.From.Bare())
}
if iq, ok := st.(*xmpp.Iq); ok {
log.Printf("iq from %s", iq.From.Bare())
}
}
}
}
示例5: ReadConfig
// Read configuration file
func ReadConfig() {
config, err := configparser.Read("/opt/pg/libnetwork/config.ini")
if err != nil {
log.Fatal(err)
}
// get PLUMgrid config
pg_section, pg_err := config.Section("PLUMgrid")
if pg_err != nil {
log.Fatal(pg_err)
} else {
vip = pg_section.ValueOf("virtual_ip")
username = pg_section.ValueOf("pg_username")
password = pg_section.ValueOf("pg_password")
default_vd = pg_section.ValueOf("default_domain")
}
// get Libnetwork config
lib_section, lib_err := config.Section("Libnetwork")
if lib_err != nil {
log.Fatal(lib_err)
} else {
scope = lib_section.ValueOf("scope")
}
}
示例6: getBinlogPath
// getBinlogPath read and parse the my.cnf config file and returns the path to the binlog file and datadir.
func (m *MySQLBinlogGrowth) getBinlogPath() (binLog string, dataDir string) {
// read my.cnf config file
config, err := configparser.Read(m.myCnfPath)
if err != nil {
m.log.Error(err)
return
}
section, err := config.Section("mysqld")
if err != nil {
m.log.Error("mysqld section missing in ", m.myCnfPath)
return
}
binLog = section.ValueOf("log-bin")
if binLog == "" {
m.log.Error("log-bin value missing from ", m.myCnfPath)
return
}
dataDir = section.ValueOf("datadir")
if dataDir == "" {
m.log.Error("datadir value missing from ", m.myCnfPath)
return
}
// If the log-bin value is a relative path then it's based on datadir
if !path.IsAbs(binLog) {
binLog = path.Join(dataDir, binLog)
}
return
}
示例7: readStorageAggregations
func readStorageAggregations(file string) ([]*StorageAggregation, error) {
config, err := cfg.Read(file)
if err != nil {
return nil, err
}
sections, err := config.AllSections()
if err != nil {
return nil, err
}
var ret []*StorageAggregation
for _, s := range sections {
var saggr StorageAggregation
// this is mildly stupid, but I don't feel like forking
// configparser just for this
saggr.name =
strings.Trim(strings.SplitN(s.String(), "\n", 2)[0], " []")
if saggr.name == "" {
continue
}
saggr.pattern, err = regexp.Compile(s.ValueOf("pattern"))
if err != nil {
logger.Logf("failed to parse pattern '%s'for [%s]: %s",
s.ValueOf("pattern"), saggr.name, err.Error())
continue
}
saggr.xFilesFactor, err = strconv.ParseFloat(s.ValueOf("xFilesFactor"), 64)
if err != nil {
logger.Logf("failed to parse xFilesFactor '%s' in %s: %s",
s.ValueOf("xFilesFactor"), saggr.name, err.Error())
continue
}
saggr.aggregationMethodStr = s.ValueOf("aggregationMethod")
switch saggr.aggregationMethodStr {
case "average", "avg":
saggr.aggregationMethod = whisper.Average
case "sum":
saggr.aggregationMethod = whisper.Sum
case "last":
saggr.aggregationMethod = whisper.Last
case "max":
saggr.aggregationMethod = whisper.Max
case "min":
saggr.aggregationMethod = whisper.Min
default:
logger.Logf("unknown aggregation method '%s'",
s.ValueOf("aggregationMethod"))
continue
}
logger.Debugf("adding aggregation [%s] pattern = %s aggregationMethod = %s xFilesFactor = %f",
saggr.name, s.ValueOf("pattern"),
saggr.aggregationMethodStr, saggr.xFilesFactor)
ret = append(ret, &saggr)
}
return ret, nil
}
示例8: ReadWhisperSchemas
// ReadWhisperSchemas reads and parses a storage-schemas.conf file and returns a sorted
// schemas structure
// see https://graphite.readthedocs.io/en/0.9.9/config-carbon.html#storage-schemas-conf
func ReadWhisperSchemas(file string) (WhisperSchemas, error) {
config, err := configparser.Read(file)
if err != nil {
return nil, err
}
sections, err := config.AllSections()
if err != nil {
return nil, err
}
var schemas WhisperSchemas
for i, sec := range sections {
schema := Schema{}
schema.Name =
strings.Trim(strings.SplitN(sec.String(), "\n", 2)[0], " []")
if schema.Name == "" || strings.HasPrefix(schema.Name, "#") {
continue
}
patternStr := sec.ValueOf("pattern")
if patternStr == "" {
return nil, fmt.Errorf("[persister] Empty pattern for [%s]", schema.Name)
}
schema.Pattern, err = regexp.Compile(patternStr)
if err != nil {
return nil, fmt.Errorf("[persister] Failed to parse pattern %q for [%s]: %s",
sec.ValueOf("pattern"), schema.Name, err.Error())
}
schema.RetentionStr = sec.ValueOf("retentions")
schema.Retentions, err = ParseRetentionDefs(schema.RetentionStr)
if err != nil {
return nil, fmt.Errorf("[persister] Failed to parse retentions %q for [%s]: %s",
sec.ValueOf("retentions"), schema.Name, err.Error())
}
priorityStr := sec.ValueOf("priority")
p := int64(0)
if priorityStr != "" {
p, err = strconv.ParseInt(priorityStr, 10, 0)
if err != nil {
return nil, fmt.Errorf("[persister] Failed to parse priority %q for [%s]: %s", priorityStr, schema.Name, err)
}
}
schema.Priority = int64(p)<<32 - int64(i) // to sort records with same priority by position in file
schemas = append(schemas, schema)
}
sort.Sort(schemas)
return schemas, nil
}
示例9: Update
func (c *config) Update() {
var err error
c.RootPath, err = osext.ExecutableFolder()
checkErr(err)
if strings.Contains(c.RootPath, "go-build") {
c.RootPath = "."
}
config, err := configparser.Read(FromRootDir("config.ini"))
checkErr(err)
mainConfig, err := config.Section("Main")
checkErr(err)
c.DefaultProfile, err = strconv.Atoi(mainConfig.ValueOf("defaultProfile"))
if err != nil {
panic("Error parse config parametr 'defaultProfile'")
}
c.AdminMail = mainConfig.ValueOf("adminMail")
c.GonderMail = mainConfig.ValueOf("gonderMail")
dbConfig, err := config.Section("Database")
checkErr(err)
c.dbType = dbConfig.ValueOf("type")
c.dbString = dbConfig.ValueOf("string")
mailerConfig, err := config.Section("Mailer")
checkErr(err)
if mailerConfig.ValueOf("send") == "yes" {
c.RealSend = true
} else {
c.RealSend = false
}
if mailerConfig.ValueOf("dnscache") == "yes" {
c.DnsCache = true
} else {
c.DnsCache = false
}
c.MaxCampaingns, err = strconv.Atoi(mailerConfig.ValueOf("maxcampaign"))
if err != nil {
panic("Error parse config parametr 'maxcampaign'")
}
statisticConfig, err := config.Section("Statistic")
checkErr(err)
apiConfig, err := config.Section("API")
checkErr(err)
c.Url = "http://" + mainConfig.ValueOf("host")
c.StatPort = statisticConfig.ValueOf("port")
c.ApiPort = apiConfig.ValueOf("port")
c.Version = "0.7.4"
}
示例10: init
// init - Establish database connection
func init() {
//database = db.GetConnection("/home/visolve/go-orm/config.ini")
conf, _ := configparser.Read("/home/visolve/go-orm/config.ini")
db_config, _ := conf.Section("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"))
}
cdatabase = abstract.Database(CouchDb{db})
}
示例11: TestOption
func TestOption(t *testing.T) {
config, err := configparser.Read("fastforward.conf")
if err != nil {
t.Error(err)
}
section, err := config.Section("DEFAULT")
if err != nil {
t.Error(err)
}
options := section.Options()
log.Printf("option names:\n%s", options["provisioning_driver"])
assert.Equal(t, "playback", options["provisioning_driver"])
}
示例12: LoadConfig
// Load config values from file
func LoadConfig(filename string) {
LoadDefaults()
log.Printf("\nLoading Configuration from %v\n", filename)
config, err := configparser.Read(filename)
fmt.Print(config)
if err != nil {
log.Fatal(err)
}
dbSection, err := config.Section("Database")
if err != nil {
log.Fatal(err)
}
logSection, err := config.Section("Logging")
if err != nil {
log.Fatal(err)
}
authSection, err := config.Section("Auth")
if err != nil {
log.Fatal(err)
}
registrySection, err := config.Section("ServiceRegistry")
if err != nil {
log.Fatal(err)
}
//Optional sections
frontendSection, err := config.Section("Frontend")
userSection, err := config.Section("Users")
searchSection, err := config.Section("Search")
notifSection, err := config.Section("Notifications")
if frontendSection != nil {
SetFrontendConfig(frontendSection)
}
if searchSection != nil {
SetSearchConfig(searchSection)
}
if userSection != nil {
setUsersConfig(userSection)
}
if notifSection != nil {
setNotificationConfig(notifSection)
}
setDbConfig(dbSection)
setLogConfig(logSection)
setAuthConfig(authSection)
setRegistryConfig(registrySection)
}
示例13: TestSection
func TestSection(t *testing.T) {
config, err := configparser.Read("fastforward.conf")
if err != nil {
t.Error(err)
}
section, err := config.Section("DEFAULT")
if err != nil {
t.Error(err)
}
log.Printf("the default section:\n%s", section)
section, err = config.Section("PLAYBACK")
if err != nil {
t.Error(err)
}
log.Printf("the playback section:\n%s", section)
}
示例14: LoadPluginData
// Loads Plugin Data from the plugins ini file
func LoadPluginData(filename string) {
readSinglePluginData := func(pluginSection *configparser.Section) *PluginData {
theData := NewPluginData()
for key, value := range pluginSection.Options() {
switch key {
case "name":
theData.Name = value
case "author":
theData.Author = value
case "version":
theData.Version = value
case "pluginDir":
theData.PluginDir = value
case "mainScript":
theData.MainScript = value
case "stylesheet":
theData.Stylesheet = value
case "enabled":
if value == "true" {
theData.Enabled = true
} else {
theData.Enabled = false
}
}
}
return theData
}
config, err := configparser.Read(filename)
if err != nil {
log.Fatal(err)
}
fmt.Print(config)
pluginSections, err := config.Find(".plugin$")
if err != nil {
log.Fatal(err)
}
for _, section := range pluginSections {
theData := readSinglePluginData(section)
if theData.Enabled {
enabledPlugins[theData.Name] = *theData
}
}
}
示例15: 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
}