示例#1
0
// readConfigString reads a given option from a given section from the
// provided config.Config instance, returning the value as a string.
// If the option is not present, then a string with the default value
// provided in 'def' is returned.
func readConfigString(configFile *config.Config, section string, option string, def string) string {
	value, err := configFile.String(section, option)
	if err != nil {
		return def
	}
	return strings.TrimSpace(value)
}
示例#2
0
// readConfigURL reads a given option from a given section from the
// provided config.Config instance, returning the value as a url.URL.
// If the option is not present, then an url.URL with the default value
// provided in the string 'def' is returned.
func readConfigURL(configFile *config.Config, section string, option string, def string) url.URL {
	value, err := configFile.String(section, option)
	if err != nil {
		url_, _ := url.Parse(def)
		return *url_
	}
	url_, err := url.Parse(value)
	if err != nil {
		log.Fatal(err)
	}
	return *url_
}
示例#3
0
// readConfigRegexp reads a given option from a given section from the
// provided config.Config instance, returning the value as a regexp.Regexp.
// If the option is not present, then a regexp.Regexp with the default value
// provided in the string 'def' is returned.
func readConfigRegexp(configFile *config.Config, section string, option string, def string) regexp.Regexp {
	value, err := configFile.String(section, option)
	if err != nil {
		regexp, _ := regexp.Compile(def)
		return *regexp
	}
	regexp, err := regexp.Compile(value)
	if err != nil {
		log.Fatal(err)
	}
	return *regexp
}
示例#4
0
文件: config.go 项目: tgulacsi/aostor
func getDir(conf *config.Config, section string, option string, realm string) (string, error) {
	path, err := conf.String(section, option)
	if err != nil {
		return "", err
	}
	if realm != "" {
		path = strings.Replace(path, "#(realm)s", realm, -1)
		if !fileExists(path) {
			err = os.MkdirAll(path, 0755)
		}
	}
	return path, err
}
示例#5
0
func new_address_matcher() *address_matcher {
	var cfg *config.Config
	var err os.Error

	// honor NOTMUCH_CONFIG
	home := os.Getenv("NOTMUCH_CONFIG")
	if home == "" {
		home = os.Getenv("HOME")
	}

	if cfg, err = config.ReadDefault(path.Join(home, ".notmuch-config")); err != nil {
		log.Fatalf("error loading config file:", err)
	}

	db_path, _ := cfg.String("database", "path")
	primary_email, _ := cfg.String("user", "primary_email")
	addrbook_tag, err := cfg.String("user", "addrbook_tag")
	if err != nil {
		addrbook_tag = "addressbook"
	}

	self := &address_matcher{db: nil,
		user_db_path:       db_path,
		user_primary_email: primary_email,
		user_addrbook_tag:  addrbook_tag}
	return self
}