本文整理汇总了Golang中github.com/kless/goconfig/config.ReadDefault函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadDefault函数的具体用法?Golang ReadDefault怎么用?Golang ReadDefault使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadDefault函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
c, err := config.ReadDefault("wiki.ini")
panicIni(err)
wikiName, err = c.String("wiki", "name")
panicIni(err)
servAddr, err := c.String("wiki", "serv_addr")
panicIni(err)
inDevMode, err = c.Bool("wiki", "dev_mode")
panicIni(err)
log.Printf("Read wiki.ini")
views = template.Must(template.ParseGlob("views/[a-z]*.html"))
log.Printf("Parsed page templates\n")
http.HandleFunc("/", rootHandler)
http.HandleFunc("/delete/", deleteHandler)
http.HandleFunc("/restore/", restoreHandler)
http.HandleFunc("/edit/", editHandler)
http.HandleFunc("/preview", previewHandler)
http.HandleFunc("/save/", saveHandler)
http.HandleFunc("/pages", pagesHandler)
http.HandleFunc("/deleted", deletedHandler)
http.HandleFunc("/versions/", versionsHandler)
http.HandleFunc("/search", searchHandler)
http.Handle("/pub/", http.StripPrefix("/pub/", http.FileServer(http.Dir("pub"))))
http.HandleFunc("/favicon.ico", faviconHandler)
log.Printf("Serving wiki pages from %s...\n", servAddr)
log.Fatal(http.ListenAndServe(servAddr, nil))
}
开发者ID:ieyasu,项目名称:go-bwiki,代码行数:29,代码来源:wiki.go
示例2: SetFile
// SetFile parses a config file. If the filename that is provided does not
// exist, the file is created and the default sections and options are written
// as comments. This function should only be called after all options are
// registered using the Register Function, so take care putting it in init
// functions.
func SetFile(fileName string) {
var err error
c, err = config.ReadDefault(fileName)
if err != nil {
WriteDefaultFile(fileName)
c, err = config.ReadDefault(fileName)
if err != nil {
panic(err)
}
}
}
开发者ID:YouthBuild-USA,项目名称:godata,代码行数:16,代码来源:config.go
示例3: NewFileStorageResolver
func NewFileStorageResolver(schemasPath, aggregationPath string) (*fileStorageResolver, error) {
resolver := new(fileStorageResolver)
schemas, err := config.ReadDefault(schemasPath)
if err != nil {
return nil, err
}
resolver.schemas = schemas
aggregation, err := config.ReadDefault(aggregationPath)
if err != nil {
return nil, err
}
resolver.aggregation = aggregation
return resolver, nil
}
开发者ID:robyoung,项目名称:go-silicon,代码行数:15,代码来源:config.go
示例4: new_address_matcher
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
}
开发者ID:alip,项目名称:notmuch,代码行数:27,代码来源:notmuch-addrlookup.go
示例5: NewConfig
// Config parser with reflection to fill fields.
//
func NewConfig(filename string) (*Config, error) {
c, e := config.ReadDefault(filename)
if e != nil {
return nil, e
}
return &Config{Config: *c}, nil
}
开发者ID:jcswart,项目名称:godock,代码行数:9,代码来源:config.go
示例6: main
func main() {
flag.Parse()
c, err := config.ReadDefault(*configFile)
if err != nil {
log.Fatal("Couldn't find the config file: ", err)
}
host, _ := c.String("network", "listen-ip")
port, _ := c.Int("network", "listen-port")
listen := fmt.Sprintf("%s:%d", host, port)
StorageLocation, err = c.String("storage", "location")
if err != nil {
StorageLocation = "./"
}
log.Println("Storing/Retrieving data from ", StorageLocation)
_, err = os.Stat(StorageLocation)
if err != nil {
log.Fatal("Folder not exist: ", err)
}
http.HandleFunc("/", DataServer)
log.Println("Server listening: ", listen)
err = http.ListenAndServe(listen, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
开发者ID:rossjones,项目名称:simple_blobstore,代码行数:31,代码来源:blobstore.go
示例7: loadConfig
//Searches for, and loads, a configuration file.
func loadConfig() *config.Config {
configDirs := strings.Split(os.Getenv("XDG_CONFIG_HOME")+":"+os.Getenv("XDG_CONFIG_DIRS"), ":")
for _, d := range configDirs {
cfg, _ := config.ReadDefault(d + "/android-notify-lite/config")
if cfg != nil {
configLocation = d + "/android-notify-lite/config"
return cfg
}
}
cfg, _ := config.ReadDefault(os.Getenv("HOME") + "/.android-notify-lite")
configLocation = os.Getenv("HOME") + "/.android-notify-lite"
if cfg == nil {
fmt.Println("Error: No configuration file found.")
os.Exit(1)
}
return cfg
}
开发者ID:sabo,项目名称:android-notify-lite,代码行数:18,代码来源:main.go
示例8: config_init
func config_init(file string) error {
f, err := os.Open(file)
defer f.Close()
if err == nil {
Config, err = config.ReadDefault(file)
main_config_file = file
}
return err
}
开发者ID:sichuanyl,项目名称:babylon,代码行数:9,代码来源:config.go
示例9: main
func main() {
flag.Parse()
c, err := config.ReadDefault(*configPath)
if err != nil {
log.Fatal(err)
os.Exit(-1)
}
pm := new(PageManager)
pm.StartServer(c)
}
开发者ID:xenji,项目名称:svn-daemon,代码行数:10,代码来源:main.go
示例10: main
func main() {
c, _ := config.ReadDefault("../../etc/config.cfg")
client_public_key, _ := c.String("Client", "public_key")
server_public_key, _ := c.String("Server", "public_key")
server_max_cores, _ := c.Int("Server", "max_cores")
fmt.Println("client public key: ", client_public_key)
fmt.Println("server public key: ", server_public_key)
fmt.Println("server max cores: ", server_max_cores)
}
开发者ID:spikebike,项目名称:Backups-Done-Right-legacy,代码行数:11,代码来源:config-test.go
示例11: loadConfig
func loadConfig() {
//read config
c, _ := config.ReadDefault("config.ini")
mode, _ = c.String("main", "mode")
server, _ = c.String("client", "server")
client_listen, _ = c.String("client", "listen")
server_listen, _ = c.String("server", "listen")
ck, _ = c.String("encrypto", "client-key")
sk, _ = c.String("encrypto", "server-key")
http_proxy, _ = c.String("client", "http-proxy")
}
开发者ID:hyqhyq3,项目名称:avsocks,代码行数:11,代码来源:main.go
示例12: init
func init() {
flag.StringVar(&CONFIGFILE, "conf", "/usr/local/shock/conf/shock.cfg", "path to config file")
flag.Parse()
c, _ := config.ReadDefault(CONFIGFILE)
// Shock
SITEPORT, _ = c.Int("Shock", "site-port")
APIPORT, _ = c.Int("Shock", "api-port")
// Admin
ADMINEMAIL, _ = c.String("Admin", "email")
SECRETKEY, _ = c.String("Admin", "secretkey")
// Directories
SITEPATH, _ = c.String("Directories", "site")
DATAPATH, _ = c.String("Directories", "data")
LOGSPATH, _ = c.String("Directories", "logs")
// Mongodb
MONGODB, _ = c.String("Mongodb", "hosts")
// parse Node-Indices
NODEIDXS = map[string]idxOpts{}
nodeIdx, _ := c.Options("Node-Indices")
for _, opt := range nodeIdx {
val, _ := c.String("Node-Indices", opt)
opts := idxOpts{}
for _, parts := range strings.Split(val, ",") {
p := strings.Split(parts, ":")
if p[0] == "unique" {
if p[1] == "true" {
opts.unique = true
} else {
opts.unique = false
}
} else if p[0] == "dropDups" {
if p[1] == "true" {
opts.dropDups = true
} else {
opts.dropDups = false
}
} else if p[0] == "sparse" {
if p[1] == "true" {
opts.sparse = true
} else {
opts.sparse = false
}
}
}
NODEIDXS[opt] = opts
}
}
开发者ID:gingi,项目名称:Shock,代码行数:51,代码来源:conf.go
示例13: ReadConfig
func ReadConfig() error {
conf, err := config.ReadDefault(ConfigFilename)
if err != nil {
return err
}
var (
repostr string
hoststr string
license string
)
AppConfig.Name, err = conf.String("variables", "name")
AppConfig.Email, err = conf.String("variables", "email")
AppConfig.HostUser, err = conf.String("general", "hostuser")
AppConfig.AltRoot, err = conf.String("general", "templates")
AppConfig.Markdown, err = conf.Bool("general", "markdown")
license, err = conf.String("general", "license")
switch license {
case "":
AppConfig.License = NilLicense
case "newbsd":
AppConfig.License = NewBSDLicense
}
repostr, err = conf.String("general", "repo")
switch repostr {
case "":
AppConfig.Repo = NilRepo
case "git":
AppConfig.Repo = Git
//case "hg":
//...
default:
AppConfig.Repo = NilRepo
}
hoststr, err = conf.String("general", "host")
switch hoststr {
case "":
AppConfig.Host = NilHost
case "github":
AppConfig.Host = GitHubHost
AppConfig.Repo = Git
//case "googlecode":
//...
default:
AppConfig.Host = NilHost
}
return nil
}
开发者ID:robteix,项目名称:gonew,代码行数:51,代码来源:config.go
示例14: LoadConfig
// LoadConfig reads and validates the server and oauth provider configuration from
// the provided config file path. If for some reason it cannot load the settings
// defined in the config file, or the config file cannot be read at all, it will
// return an error.
func LoadConfig(path string) error {
// load config file
configFile, err := config.ReadDefault(path)
if err != nil {
log.Fatal("Can't read config file:", err)
}
// validate server configuration
serverConfig.ListenAddress = readConfigString(configFile, "server", "ListenAddress", "localhost:8080")
serverConfig.ListenAddressTLS = readConfigString(configFile, "server", "ListenAddressTLS", "localhost:4443")
if serverConfig.ListenAddress == "" && serverConfig.ListenAddressTLS == "" {
return errors.New("At least one of ListenAddress or ListenAddressTLS must be present")
}
// Validate certs if SSL is enabled
if serverConfig.ListenAddressTLS != "" {
serverConfig.SSLCert = readConfigString(configFile, "server", "SSLCert", "")
serverConfig.SSLKey = readConfigString(configFile, "server", "SSLKey", "")
if serverConfig.SSLCert == "" {
return errors.New("A SSL Certificate is required")
}
if serverConfig.SSLKey == "" {
return errors.New("A SSL Key is required")
}
}
serverConfig.CallbackPath = readConfigString(configFile, "server", "CallbackPath", "/oauth2callback")
serverConfig.ProtectPath = readConfigString(configFile, "server", "ProtectPath", "/")
serverConfig.CookieName = readConfigString(configFile, "server", "CookieName", "oauthproxy")
serverConfig.ProxyURL = readConfigURL(configFile, "server", "ProxyURL", "http://example.com/")
// Validate OAuth settings
oauthProviderConfig.EmailRegexp = readConfigRegexp(configFile, "oauth", "EmailRegexp", ".*")
oauthProviderConfig.oauthConfig.ClientId = readConfigString(configFile, "oauth", "ClientId", "")
oauthProviderConfig.oauthConfig.ClientSecret = readConfigString(configFile, "oauth", "ClientSecret", "")
scope := readConfigURL(configFile, "oauth", "Scope", "https://www.googleapis.com/auth/userinfo.email")
oauthProviderConfig.oauthConfig.Scope = scope.String()
authURL := readConfigURL(configFile, "oauth", "AuthURL", "https://accounts.google.com/o/oauth2/auth")
oauthProviderConfig.oauthConfig.AuthURL = authURL.String()
tokenURL := readConfigURL(configFile, "oauth", "TokenURL", "https://accounts.google.com/o/oauth2/token")
oauthProviderConfig.oauthConfig.TokenURL = tokenURL.String()
redirectURL := readConfigURL(configFile, "oauth", "RedirectURL", "http://testsite.com/oauth2callback")
oauthProviderConfig.oauthConfig.RedirectURL = redirectURL.String()
userInfoAPI := readConfigURL(configFile, "oauth", "UserInfoAPI", "https://www.googleapis.com/oauth2/v1/userinfo")
oauthProviderConfig.UserInfoAPI = userInfoAPI.String()
return nil
}
开发者ID:msurdi,项目名称:oauthproxy,代码行数:51,代码来源:config.go
示例15: read_config
func read_config() {
if len(os.Args) == 1 {
panic("config")
}
cf := os.Args[1]
conf, err := config.ReadDefault(cf)
if err != nil {
panic("config")
}
binlog_root_path, err = conf.String("DEFAULT", "base_path")
if err != nil {
panic("config")
}
root_path, err = conf.String("DEFAULT", "store_path0")
if err != nil {
panic("config")
}
}
开发者ID:richmonkey,项目名称:fastdfs-go,代码行数:18,代码来源:storage.go
示例16: getConfig
// Setup a config type from a filename.
func getConfig(configFileLoc string) (c *vafanConfig) {
c = &vafanConfig{}
file, err := config.ReadDefault(configFileLoc)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed reading configuration: %v", err)
panic(err)
}
c.file = file
// default
c.baseDir = c.getString("default", "base-dir")
c.host = c.getString("default", "host")
c.port = c.getString("default", "port")
c.youtubeDevKey = c.getString("default", "youtube-dev-key")
// twitter
tw := twitterConfig{}
tw.user = c.getString("twitter", "user")
tw.password = c.getString("twitter", "password")
tw.consumerKey = c.getString("twitter", "consumer-key")
tw.consumerSecret = c.getString("twitter", "consumer-secret")
tw.accessToken = c.getString("twitter", "access-token")
tw.accessSecret = c.getString("twitter", "access-secret")
c.twitter = tw
// mysql
my := mysqlConfig{}
my.user = c.getString("mysql", "user")
my.password = c.getString("mysql", "password")
c.mysql = my
// redis
rd := redisConfig{}
rd.address = c.getString("redis", "address")
c.redis = rd
return
}
开发者ID:saulhoward,项目名称:vafan,代码行数:39,代码来源:config.go
示例17: UserConfig
// UserConfig loads configuration per user, if any.
func (c *Conf) UserConfig() error {
home := os.Getenv("HOME")
if home == "" {
return fmt.Errorf("environment variable $HOME is not set")
}
pathUserConfig := filepath.Join(home, _USER_CONFIG)
// To know if the file exist.
switch stat, err := os.Stat(pathUserConfig); {
case os.IsNotExist(err):
return nil
case stat.Mode()&os.ModeType != 0:
return fmt.Errorf("expected file: %s", _USER_CONFIG)
}
cfg, err := config.ReadDefault(pathUserConfig)
if err != nil {
return fmt.Errorf("error parsing configuration: %s", err)
}
// == Get values
var errKeys []string
ok := true
if c.Org == "" {
if c.Org, err = cfg.String("DEFAULT", "org"); err != nil {
ok = false
errKeys = append(errKeys, "org")
}
}
if c.Author == "" {
if c.Author, err = cfg.String("DEFAULT", "author"); err != nil {
ok = false
errKeys = append(errKeys, "author")
}
}
if c.Email == "" {
if c.Email, err = cfg.String("DEFAULT", "email"); err != nil {
ok = false
errKeys = append(errKeys, "email")
}
}
if c.License == "" {
if c.License, err = cfg.String("DEFAULT", "license"); err != nil {
ok = false
errKeys = append(errKeys, "license")
}
}
if c.VCS == "" {
if c.VCS, err = cfg.String("DEFAULT", "vcs"); err != nil {
ok = false
errKeys = append(errKeys, "vcs")
}
}
if len(c.ImportPaths) == 0 {
var imports string
if imports, err = cfg.String("DEFAULT", "import"); err != nil {
ok = false
errKeys = append(errKeys, "import")
} else {
c.ImportPaths = strings.Split(imports, ":")
}
}
if !ok {
return fmt.Errorf("error at user configuration: %s\n",
strings.Join(errKeys, ","))
}
return nil
}
开发者ID:matrixik,项目名称:wizard,代码行数:73,代码来源:config.go
示例18: Errplane_main
func Errplane_main(defaults econfig.Consts) {
fmt.Printf("ERRPlane Local Agent starting, Version %s \n", defaults.Current_build)
goopt.Description = func() string {
return "ERRPlane Local Agent."
}
goopt.Version = defaults.Current_build
goopt.Summary = "ErrPlane Log and System Monitor"
goopt.Parse(nil)
var fconfig_file string
fconfig_file = *config_file
fmt.Printf("Loading config file %s.\n", fconfig_file)
c, err := config.ReadDefault(fconfig_file)
if err != nil {
log.Fatal("Can not find the Errplane Config file, please install it in /etc/ranger/ranger.conf.")
}
api_key, _ := c.String("DEFAULT", "api_key")
if len(*install_api_key) > 1 {
fmt.Printf("Saving new Config!\n")
c.AddOption("DEFAULT", "api_key", *install_api_key)
c.WriteFile(fconfig_file, 0644, "")
c, err := config.ReadDefault(fconfig_file)
if err != nil {
log.Fatal("Can not find the Errplane Config file, please install it in /etc/ranger/ranger.conf.")
}
api_key, _ = c.String("DEFAULT", "api_key")
}
if len(api_key) < 1 {
log.Fatal("No api key found. Please rerun this with --install-api-key <api_key_here> ")
os.Exit(1)
}
if !*amForeground {
//Daemonizing requires root
if os.Getuid() == 0 {
daemonize.Do_fork(os.Args[0], fconfig_file)
l4g.Fine("Exiting parent process-%s\n", os.Args[0])
os.Exit(0)
} else {
fmt.Printf("Daemoning requires root \n")
os.Exit(1)
}
}
setup_logger()
api_url, _ := c.String("DEFAULT", "api_host")
config_url, _ := c.String("DEFAULT", "config_host")
output_dir, _ := c.String("DEFAULT", "agent_path")
if len(output_dir) < 1 {
output_dir = "/usr/local/ranger/"
}
agent_bin, _ := c.String("DEFAULT", "agent_bin")
if len(agent_bin) < 1 {
agent_bin = "/usr/local/bin/ranger-local-agent"
}
pid_location, _ := c.String("DEFAULT", "pid_file")
if len(pid_location) < 1 {
pid_location = "/var/run/ranger/ranger.pid"
}
auto_update, _ := c.String("DEFAULT", "auto_upgrade")
write_pid(pid_location)
config_data := econfig.ParseJsonFromHttp(config_url, api_key)
l4g.Debug("Expected agent version-%s\n", config_data.Version)
if auto_update == "true" && config_data.Version != defaults.Current_build {
econfig.Upgrade_version(config_data.Version, config_data.Sha256, output_dir, agent_bin, defaults)
os.Exit(1)
} else {
l4g.Debug("Don't need to upgrade versions\n")
}
_, err = exec.LookPath("tail")
if err != nil {
log.Fatal("installing tail is in your future")
// exit(1)
}
configChan := make(chan *econfig.AgentConfigType)
go theBrain(configChan, api_key, api_url)
go econfig.CheckForUpdatedConfigs(auto_update, config_url, api_key, output_dir, agent_bin, configChan, defaults)
if err != nil {
log.Fatal(err)
}
err = nil
for err == nil {
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:ranger-1,代码行数:101,代码来源:local_agent.go
示例19: main
func main() {
goopt.Version = version
goopt.Summary = "send emc vnx performance data to graphite"
goopt.Parse(nil)
if f, _ := exists(*opt_conf); f == false {
fmt.Print(goopt.Help())
fmt.Println("ERROR: config file " + *opt_conf + " doesn't exist")
return
}
c, _ := config.ReadDefault(*opt_conf)
host, _ := c.String("graphite", "host")
port, _ := c.Int("graphite", "port")
timeout, _ := c.Int("graphite", "timeout")
basename, _ := c.String("graphite", "basename")
//todo: we also can parse this from the output...
timestamp := time.Now().Unix()
log(fmt.Sprintf("using graphite with host %s:%d", host, port))
if f, _ := exists(*opt_data); f == false {
fmt.Print(goopt.Help())
fmt.Println("ERROR: data file " + *opt_data + " doesn't exist")
return
}
lines, err := readLines(*opt_data)
if err != nil {
fmt.Println("ERROR:", err)
return
}
//we only want to use the head and the first line of data
head := strings.Split(lines[0], ",")
data := strings.Split(lines[1], ",")
if len(head) != len(data) {
fmt.Println("ERROR: malformed csv (length of head != length of data")
return
}
//create the graphite connection.
// Todo: export this in a small pkg
cstr := fmt.Sprintf("%s:%d", host, port)
log("trying to connect to " + cstr)
conn, err := net.DialTimeout("tcp", cstr, time.Duration(timeout)*time.Second)
if err != nil {
fmt.Println("ERROR:", err)
return
}
for n, val := range head {
key := stringify(val)
value := stringify(data[n])
if key != "Timestamp" {
msg := fmt.Sprintf("%s.%s.%s.%s %s %d", basename, *opt_mover, *opt_statsname, key, value, timestamp)
log("sending: " + msg)
fmt.Fprint(conn, "\n"+msg+"\n")
} else {
log("Timestamp: ... next...")
}
}
conn.Close()
}
开发者ID:koumdros,项目名称:vnx2graphite,代码行数:65,代码来源:vnx2graphite.go
示例20: loadConf
func loadConf(conf string) (*config.Config, error) {
return config.ReadDefault(conf)
}
开发者ID:funkygao,项目名称:dlogmon,代码行数:3,代码来源:conf.go
注:本文中的github.com/kless/goconfig/config.ReadDefault函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论