• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang conf.ConfigFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getPasswords

func getPasswords(c *conf.ConfigFile) ([]string, error) {
	passwords, err := c.GetString("default", "passwords")
	if err != nil {
		return nil, err
	}
	return strings.Split(passwords, " "), nil
}
开发者ID:petemoore,项目名称:runlib,代码行数:7,代码来源:setup_windows.go


示例2: GetStorage

func GetStorage(config *conf.ConfigFile) (Storage, error) {
	storageMethod, err := config.GetString("storage", "method")
	if err != nil {
		return nil, errors.New("Error: storage method not specified in config file.")
	}

	var storage Storage

	switch storageMethod {
	case "local":
		storage, err = NewLocalStorage(config)
	case "ftp":
		storage, err = NewFTPStorage(config)
	case "gdrive":
		storage, err = NewGDriveStorage(config)
	default:
		return nil, errors.New("Error: storage method '" + storageMethod + "' not found.")
	}

	if err != nil {
		return nil, err
	}

	return storage, nil
}
开发者ID:vichetuc,项目名称:asink,代码行数:25,代码来源:storage.go


示例3: getInt

func getInt(c *conf.ConfigFile, section, option string) (value int) {
	value, err := c.GetInt(section, option)
	if err != nil {
		log.Fatal("missing config value: ", option)
	}
	return
}
开发者ID:warrior1724,项目名称:check-receiver,代码行数:7,代码来源:config.go


示例4: NewFTPStorage

func NewFTPStorage(config *conf.ConfigFile) (*FTPStorage, error) {
	server, err := config.GetString("storage", "server")
	if err != nil {
		return nil, errors.New("Error: FTPStorage indicated in config file, but 'server' not specified.")
	}
	port, err := config.GetInt("storage", "port")
	if err != nil {
		return nil, errors.New("Error: FTPStorage indicated in config file, but 'port' not specified.")
	}
	directory, err := config.GetString("storage", "directory")
	if err != nil {
		return nil, errors.New("Error: FTPStorage indicated in config file, but 'directory' not specified.")
	}
	username, err := config.GetString("storage", "username")
	if err != nil {
		return nil, errors.New("Error: FTPStorage indicated in config file, but 'username' not specified.")
	}
	password, err := config.GetString("storage", "password")
	if err != nil {
		return nil, errors.New("Error: FTPStorage indicated in config file, but 'password' not specified.")
	}

	fs := new(FTPStorage)
	fs.server = server
	fs.port = port
	fs.directory = directory
	fs.username = username
	fs.password = password

	fs.connectionsChan = make(chan int, FTP_MAX_CONNECTIONS)

	return fs, nil
}
开发者ID:vichetuc,项目名称:asink,代码行数:33,代码来源:storage_ftp.go


示例5: sendMail

func sendMail(c *conf.ConfigFile, e Envelope) error {
	var addr string
	var err error
	var conn *smtp.Client

	addr, _ = c.GetString("main", "smtp")

	conn, err = smtp.Dial(addr)
	if err != nil {
		return err
	}

	if err = conn.Mail(e.Sender); err != nil {
		return err
	}

	for _, addr := range e.Recipients {
		if err = conn.Rcpt(addr); err != nil {
			return err
		}
	}

	w, err := conn.Data()
	if err != nil {
		return err
	}

	io.Copy(w, serializeMail(e))
	conn.Quit()
	return nil
}
开发者ID:sprungknoedl,项目名称:postcrypt,代码行数:31,代码来源:encrypt.go


示例6: getIdsByEmails

func getIdsByEmails(c *conf.ConfigFile, k openpgp.EntityList, emails []string) (ids []string) {
	var emailsLeft []string

	for _, email := range emails {
		if c.HasOption("keys", email) {
			line, _ := c.GetString("keys", email)
			parts := strings.Fields(line)
			ids = append(ids, parts...)
		} else {
			emailsLeft = append(emailsLeft, email)
		}
	}

	for _, entity := range k {
		for _, identity := range entity.Identities {
			for _, email := range emailsLeft {
				if identity.UserId.Email == email {
					ids = append(ids, getKeyId(entity))
					continue // enough if one addr per key matches
				}
			}
		}
	}

	return ids
}
开发者ID:sprungknoedl,项目名称:postcrypt,代码行数:26,代码来源:util.go


示例7: LoadRestAddr

func LoadRestAddr(c *conf.ConfigFile) (string, error) {
	addr, err := c.GetString("WebFrontend", "addr")
	if err != nil || addr == "" {
		addr = "localhost:9898"
		err = nil
	}
	return addr, err
}
开发者ID:philippwinkler,项目名称:uniqush-push,代码行数:8,代码来源:configparser.go


示例8: getPasswords

func getPasswords(c *conf.ConfigFile) ([]string, error) {
	count, err := c.GetInt("default", "sandboxCount")
	if err != nil {
		return nil, err
	}
	result := make([]string, count)
	for i := range result {
		result[i] = "password" + strconv.Itoa(i)
	}
	return result, nil
}
开发者ID:petemoore,项目名称:runlib,代码行数:11,代码来源:service_linux.go


示例9: LoadLoggers

func LoadLoggers(c *conf.ConfigFile) (loggers []Logger, err error) {
	var logfile io.Writer

	logfilename, err := c.GetString("default", "logfile")
	if err == nil && logfilename != "" {
		logfile, err = os.OpenFile(logfilename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
		if err != nil {
			logfile = os.Stderr
		}
	} else {
		logfile = os.Stderr
	}

	loggers = make([]Logger, LOGGER_NR_LOGGERS)
	loggers[LOGGER_WEB], err = loadLogger(logfile, c, "WebFrontend", "[WebFrontend]")
	if err != nil {
		loggers = nil
		return
	}

	loggers[LOGGER_ADDPSP], err = loadLogger(logfile, c, "AddPushServiceProvider", "[AddPushServiceProvider]")
	if err != nil {
		loggers = nil
		return
	}

	loggers[LOGGER_RMPSP], err = loadLogger(logfile, c, "RemovePushServiceProvider", "[RemovePushServiceProvider]")
	if err != nil {
		loggers = nil
		return
	}

	loggers[LOGGER_SUB], err = loadLogger(logfile, c, "Subscribe", "[Subscribe]")
	if err != nil {
		loggers = nil
		return
	}

	loggers[LOGGER_UNSUB], err = loadLogger(logfile, c, "Unsubscribe", "[Unsubscribe]")
	if err != nil {
		loggers = nil
		return
	}

	loggers[LOGGER_PUSH], err = loadLogger(logfile, c, "Push", "[Push]")
	if err != nil {
		loggers = nil
		return
	}
	return
}
开发者ID:philippwinkler,项目名称:uniqush-push,代码行数:51,代码来源:configparser.go


示例10: configureSandboxes

func configureSandboxes(config *conf.ConfigFile) ([]SandboxPair, error) {
	basePath, err := config.GetString("default", "path")
	if err != nil {
		return nil, err
	}
	passwords, err := getPasswords(config)
	if err != nil {
		return nil, err
	}
	result := make([]SandboxPair, len(passwords))
	for index, password := range passwords {
		localBase := filepath.Join(basePath, strconv.Itoa(index))
		result[index].Compile.Path = filepath.Join(localBase, "C")
		result[index].Run.Path = filepath.Join(localBase, "R")

		e := checkSandbox(result[index].Compile.Path)
		if e != nil {
			return nil, e
		}
		e = checkSandbox(result[index].Run.Path)
		if e != nil {
			return nil, e
		}

		if PLATFORM_ID == "linux" {
			e = setAcl(result[index].Compile.Path, "compiler")
			if e != nil {
				return nil, e
			}
			result[index].Compile.Login, e = subprocess.NewLoginInfo("compiler", "compiler")
			if e != nil {
				return nil, e
			}
		}

		restrictedUser := "tester" + strconv.Itoa(index)

		e = setAcl(result[index].Run.Path, restrictedUser)
		if e != nil {
			return nil, e
		}
		// HACK HACK: on linux, passwords are ignored.
		result[index].Run.Login, e = subprocess.NewLoginInfo(restrictedUser, password)
		if e != nil {
			return nil, e
		}
	}
	return result, nil
}
开发者ID:petemoore,项目名称:runlib,代码行数:49,代码来源:service.go


示例11: initTemplates

func initTemplates(conf *conf.ConfigFile) {
	tmplDir, err := conf.GetString("default", "tmpl_dir")
	if err != nil {
		log.Panicf("not specified tmpl_dir: %s", err)
	}

	registerTmpl = getTemplate(tmplDir, "register")
	loginTmpl = getTemplate(tmplDir, "login")
}
开发者ID:v-sh,项目名称:gotwit,代码行数:9,代码来源:httpServe.go


示例12: startServer

func startServer(conf *conf.ConfigFile) {
	http.Handle("/", http.HandlerFunc(rootHandler))
	http.Handle("/login/", http.HandlerFunc(loginHandler))
	http.Handle("/register/", http.HandlerFunc(registerHandler))
	host, err := conf.GetString("default", "host")
	if err != nil {
		log.Panic("not specified host")
	}
	port, _ := conf.GetString("default", "port")
	if err != nil {
		log.Panic("not specified port")
	}
	err = http.ListenAndServe(host+":"+port, nil)
	if err != nil {
		log.Fatal("ListernAndServe:", err)
	}

}
开发者ID:v-sh,项目名称:gotwit,代码行数:18,代码来源:httpServe.go


示例13: getKeys

func getKeys(c *conf.ConfigFile, e Envelope) openpgp.EntityList {
	var ids []string
	var path string
	var fh *os.File
	var err error
	var k openpgp.EntityList

	path, _ = c.GetString("main", "keyring")

	fh, err = os.Open(path)
	if err != nil {
		panic(err)
	}

	k, err = openpgp.ReadKeyRing(fh)
	if err != nil {
		panic(err)
	}

	ids = getIdsByEmails(c, k, e.Recipients)
	return getKeysByIds(k, ids)
}
开发者ID:sprungknoedl,项目名称:postcrypt,代码行数:22,代码来源:encrypt.go


示例14: NewLocalStorage

func NewLocalStorage(config *conf.ConfigFile) (*LocalStorage, error) {
	storageDir, err := config.GetString("storage", "dir")
	if err != nil {
		return nil, errors.New("Error: LocalStorage indicated in config file, but lacking local storage directory ('dir = some/dir').")
	}

	ls := new(LocalStorage)
	ls.storageDir = storageDir
	ls.tmpSubdir = path.Join(storageDir, ".asink-tmpdir")

	//make sure the base directory and tmp subdir exist
	err = util.EnsureDirExists(ls.storageDir)
	if err != nil {
		return nil, err
	}
	err = util.EnsureDirExists(ls.tmpSubdir)
	if err != nil {
		return nil, err
	}

	return ls, nil
}
开发者ID:vichetuc,项目名称:asink,代码行数:22,代码来源:storage_local.go


示例15: loadLogger

func loadLogger(writer io.Writer, c *conf.ConfigFile, field string, prefix string) (Logger, error) {
	var loglevel string
	var logswitch bool
	var err error

	logswitch, err = c.GetBool(field, "log")
	if err != nil {
		logswitch = true
	}

	if writer == nil {
		writer = os.Stderr
	}

	loglevel, err = c.GetString(field, "loglevel")
	if err != nil {
		loglevel = "standard"
	}
	var level int

	if logswitch {
		switch strings.ToLower(loglevel) {
		case "standard":
			level = LOGLEVEL_INFO
		case "verbose":
			level = LOGLEVEL_INFO
		case "debug":
			level = LOGLEVEL_DEBUG
		default:
			level = LOGLEVEL_INFO
		}
	} else {
		level = LOGLEVEL_SILENT
	}

	logger := NewLogger(writer, prefix, level)
	return logger, nil
}
开发者ID:philippwinkler,项目名称:uniqush-push,代码行数:38,代码来源:configparser.go


示例16: GetAndInitDB

func GetAndInitDB(config *conf.ConfigFile) (*AsinkDB, error) {
	dbLocation, err := config.GetString("local", "dblocation")
	if err != nil {
		return nil, errors.New("Error: database location not specified in config file.")
	}

	db, err := sql.Open("sqlite3", "file:"+dbLocation+"?cache=shared&mode=rwc")
	if err != nil {
		return nil, err
	}

	//make sure the events table is created
	tx, err := db.Begin()
	if err != nil {
		return nil, err
	}
	rows, err := tx.Query("SELECT name FROM sqlite_master WHERE type='table' AND name='events';")
	if err != nil {
		return nil, err
	}
	if !rows.Next() {
		//if this is false, it means no rows were returned
		tx.Exec("CREATE TABLE events (id INTEGER, localid INTEGER PRIMARY KEY ASC, type INTEGER, localstatus INTEGER, path TEXT, hash TEXT, predecessor TEXT, timestamp INTEGER, permissions INTEGER);")
		//		tx.Exec("CREATE INDEX IF NOT EXISTS localididx on events (localid)")
		tx.Exec("CREATE INDEX IF NOT EXISTS ididx on events (id);")
		tx.Exec("CREATE INDEX IF NOT EXISTS pathidx on events (path);")
	}
	err = tx.Commit()
	if err != nil {
		return nil, err
	}

	ret := new(AsinkDB)
	ret.db = db
	return ret, nil
}
开发者ID:vichetuc,项目名称:asink,代码行数:36,代码来源:database.go


示例17: NewGDriveStorage

func NewGDriveStorage(config *conf.ConfigFile) (*GDriveStorage, error) {
	cachefile, err := config.GetString("storage", "cachefile")
	if err != nil {
		return nil, errors.New("Error: GDriveStorage indicated in config file, but 'cachefile' not specified.")
	}

	code, err := config.GetString("storage", "oauth_code")
	if err != nil {
		code = ""
	}

	directory, err := config.GetString("storage", "directory")
	if err != nil {
		return nil, errors.New("Error: GDriveStorage indicated in config file, but 'directory' not specified.")
	}

	oauth_config := &oauth.Config{
		ClientId:     GDRIVE_CLIENT_ID,
		ClientSecret: GDRIVE_CLIENT_SECRET,
		RedirectURL:  "urn:ietf:wg:oauth:2.0:oob",
		Scope:        "https://www.googleapis.com/auth/drive",
		AuthURL:      "https://accounts.google.com/o/oauth2/auth",
		TokenURL:     "https://accounts.google.com/o/oauth2/token",
		TokenCache:   oauth.CacheFile(cachefile),
	}

	transport := &oauth.Transport{Config: oauth_config}
	token, err := oauth_config.TokenCache.Token()
	if err != nil {
		//if a code wasn't specified in the config file, ask the user to do that
		if code == "" {
			url := oauth_config.AuthCodeURL("")
			return nil, errors.New(fmt.Sprintf("Visit the following URL and sign in using your Google account to get an authorization code allowing Asink to access your GDrive files. Be sure to add this code to your Asink config file as 'oauth_code = your_code_here' before re-starting Asink:\n%s\n", url))
		}

		//attempt to fetch a token using the user-supplied code (this
		//has the effect of caching the token in the specified cache
		//file)
		token, err = transport.Exchange(code)
		if err != nil {
			url := oauth_config.AuthCodeURL("")
			return nil, errors.New(fmt.Sprintf("Error exchanging user-supplied GDrive code for an authentication token. Please check your auth code supplied in the Asink config file, or consider obtaining another by visiting %s\n(%s)", url, err.Error()))
		}
	}

	//Now, actually initialize the GDrive part of the API
	transport.Token = token
	s, err := drive.New(transport.Client())
	if err != nil {
		return nil, err
	}

	folderlist, err := s.Files.List().Q("mimeType = 'application/vnd.google-apps.folder' and title = '" + directory + "'").Do()

	if len(folderlist.Items) < 1 {
		//try to create a folder named 'directory'
		f := &drive.File{Title: directory, Description: "Asink client folder", MimeType: "application/vnd.google-apps.folder"}
		f, err := s.Files.Insert(f).Do()

		folderlist, err = s.Files.List().Q("mimeType = 'application/vnd.google-apps.folder' and title = '" + directory + "'").Do()
		if err != nil {
			return nil, err
		} else if len(folderlist.Items) < 1 {
			return nil, errors.New("I was unable to create a new folder in your GDrive, but I'm not sure why")
		}
	} else if len(folderlist.Items) > 1 {
		return nil, errors.New(fmt.Sprintf("Error: Your GDrive has more than one directory named '%s'. You are a barbarian. Fix that and we'll talk. (check your trash if you can't find it)\n", directory))
	}

	folderid := folderlist.Items[0].Id

	gs := new(GDriveStorage)
	gs.cachefile = cachefile
	gs.directory = directory
	gs.auth_code = code
	gs.service = s
	gs.transport = transport
	gs.folderid = folderid
	return gs, nil
}
开发者ID:vichetuc,项目名称:asink,代码行数:80,代码来源:storage_gdrive.go


示例18: ParseCfgDefaultCDRStatsConfig

// Parse the configuration file for CDRStatConfigs
func ParseCfgDefaultCDRStatsConfig(c *conf.ConfigFile) (*CdrStatsConfig, error) {
	var err error
	csCfg := NewCdrStatsConfigWithDefaults()
	if hasOpt := c.HasOption("cdrstats", "queue_length"); hasOpt {
		csCfg.QueueLength, _ = c.GetInt("cdrstats", "queue_length")
	}
	if hasOpt := c.HasOption("cdrstats", "time_window"); hasOpt {
		durStr, _ := c.GetString("cdrstats", "time_window")
		if csCfg.TimeWindow, err = utils.ParseDurationWithSecs(durStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "metrics"); hasOpt {
		metricsStr, _ := c.GetString("cdrstats", "metrics")
		if csCfg.Metrics, err = ConfigSlice(metricsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "setup_interval"); hasOpt {
		setupIntervalStr, _ := c.GetString("cdrstats", "setup_interval")
		if len(setupIntervalStr) != 0 { // If we parse empty, will get empty time, we prefer nil
			if setupIntervalSlc, err := ConfigSlice(setupIntervalStr); err != nil {
				return nil, err
			} else {
				for _, setupTimeStr := range setupIntervalSlc {
					if setupTime, err := utils.ParseTimeDetectLayout(setupTimeStr); err != nil {
						return nil, err
					} else {
						csCfg.SetupInterval = append(csCfg.SetupInterval, setupTime)
					}
				}
			}
		}
	}
	if hasOpt := c.HasOption("cdrstats", "tors"); hasOpt {
		torsStr, _ := c.GetString("cdrstats", "tors")
		if csCfg.TORs, err = ConfigSlice(torsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "cdr_hosts"); hasOpt {
		valsStr, _ := c.GetString("cdrstats", "cdr_hosts")
		if csCfg.CdrHosts, err = ConfigSlice(valsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "cdr_sources"); hasOpt {
		valsStr, _ := c.GetString("cdrstats", "cdr_sources")
		if csCfg.CdrSources, err = ConfigSlice(valsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "req_types"); hasOpt {
		valsStr, _ := c.GetString("cdrstats", "req_types")
		if csCfg.ReqTypes, err = ConfigSlice(valsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "directions"); hasOpt {
		valsStr, _ := c.GetString("cdrstats", "directions")
		if csCfg.Directions, err = ConfigSlice(valsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "tenants"); hasOpt {
		valsStr, _ := c.GetString("cdrstats", "tenants")
		if csCfg.Tenants, err = ConfigSlice(valsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "categories"); hasOpt {
		valsStr, _ := c.GetString("cdrstats", "categories")
		if csCfg.Categories, err = ConfigSlice(valsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "accounts"); hasOpt {
		valsStr, _ := c.GetString("cdrstats", "accounts")
		if csCfg.Accounts, err = ConfigSlice(valsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "subjects"); hasOpt {
		valsStr, _ := c.GetString("cdrstats", "subjects")
		if csCfg.Subjects, err = ConfigSlice(valsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "destination_prefixes"); hasOpt {
		valsStr, _ := c.GetString("cdrstats", "destination_prefixes")
		if csCfg.DestinationPrefixes, err = ConfigSlice(valsStr); err != nil {
			return nil, err
		}
	}
	if hasOpt := c.HasOption("cdrstats", "usage_interval"); hasOpt {
		usageIntervalStr, _ := c.GetString("cdrstats", "usage_interval")
		if usageIntervalSlc, err := ConfigSlice(usageIntervalStr); err != nil {
			return nil, err
		} else {
//.........这里部分代码省略.........
开发者ID:intralanman,项目名称:cgrates,代码行数:101,代码来源:cdrstatsconfig.go


示例19: ParseCfgDerivedCharging

// Parse the configuration file and returns utils.DerivedChargers instance if no errors
func ParseCfgDerivedCharging(c *conf.ConfigFile) (dcs utils.DerivedChargers, err error) {
	var runIds, runFilters, reqTypeFlds, directionFlds, tenantFlds, torFlds, acntFlds, subjFlds, dstFlds, sTimeFlds, aTimeFlds, durFlds []string
	cfgVal, _ := c.GetString("derived_charging", "run_ids")
	if runIds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "run_filters")
	if runFilters, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "reqtype_fields")
	if reqTypeFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "direction_fields")
	if directionFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "tenant_fields")
	if tenantFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "category_fields")
	if torFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "account_fields")
	if acntFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "subject_fields")
	if subjFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "destination_fields")
	if dstFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "setup_time_fields")
	if sTimeFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "answer_time_fields")
	if aTimeFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	cfgVal, _ = c.GetString("derived_charging", "usage_fields")
	if durFlds, err = ConfigSlice(cfgVal); err != nil {
		return nil, err
	}
	// We need all to be the same length
	if len(runFilters) != len(runIds) ||
		len(reqTypeFlds) != len(runIds) ||
		len(directionFlds) != len(runIds) ||
		len(tenantFlds) != len(runIds) ||
		len(torFlds) != len(runIds) ||
		len(acntFlds) != len(runIds) ||
		len(subjFlds) != len(runIds) ||
		len(dstFlds) != len(runIds) ||
		len(sTimeFlds) != len(runIds) ||
		len(aTimeFlds) != len(runIds) ||
		len(durFlds) != len(runIds) {
		return nil, errors.New("<ConfigSanity> Inconsistent fields length in derivated_charging section")
	}
	// Create the individual chargers and append them to the final instance
	dcs = make(utils.DerivedChargers, 0)
	if len(runIds) == 1 && len(runIds[0]) == 0 { // Avoid iterating on empty runid
		return dcs, nil
	}
	for runIdx, runId := range runIds {
		dc, err := utils.NewDerivedCharger(runId, runFilters[runIdx], reqTypeFlds[runIdx], directionFlds[runIdx], tenantFlds[runIdx], torFlds[runIdx],
			acntFlds[runIdx], subjFlds[runIdx], dstFlds[runIdx], sTimeFlds[runIdx], aTimeFlds[runIdx], durFlds[runIdx])
		if err != nil {
			return nil, err
		}
		if dcs, err = dcs.Append(dc); err != nil {
			return nil, err
		}
	}
	return dcs, nil
}
开发者ID:intralanman,项目名称:cgrates,代码行数:82,代码来源:helpers.go


示例20: LoadDatabaseConfig

func LoadDatabaseConfig(cf *conf.ConfigFile) (*DatabaseConfig, error) {
	var err error
	c := new(DatabaseConfig)
	c.PushServiceManager = GetPushServiceManager()
	c.Engine, err = cf.GetString("Database", "engine")
	if err != nil || c.Engine == "" {
		c.Engine = "redis"
	}
	c.Name, err = cf.GetString("Database", "name")
	if err != nil || c.Name == "" {
		c.Name = "0"
	}
	c.Port, err = cf.GetInt("Database", "port")
	if err != nil || c.Port <= 0 {
		c.Port = -1
	}
	c.Host, err = cf.GetString("Database", "host")
	if err != nil || c.Host == "" {
		c.Host = "localhost"
	}
	c.Password, err = cf.GetString("Database", "password")
	if err != nil {
		c.Password = ""
	}
	i, e := cf.GetInt("Database", "everysec")
	c.EverySec = int64(i)
	if e != nil || c.EverySec <= 60 {
		c.EverySec = 600
	}
	c.LeastDirty, err = cf.GetInt("Database", "leastdirty")
	if err != nil || c.LeastDirty < 0 {
		c.LeastDirty = 10
	}
	c.CacheSize, err = cf.GetInt("Database", "cachesize")
	if err != nil || c.CacheSize < 0 {
		c.CacheSize = 1024
	}

	return c, nil
}
开发者ID:philippwinkler,项目名称:uniqush-push,代码行数:40,代码来源:configparser.go



注:本文中的code/google/com/p/goconf/conf.ConfigFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang dec.Dec类代码示例发布时间:2022-05-24
下一篇:
Golang conf.ReadConfigFile函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap