本文整理汇总了Golang中github.com/kless/goconfig/config.ReadDefault函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadDefault函数的具体用法?Golang ReadDefault怎么用?Golang ReadDefault使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadDefault函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
示例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)
}
}
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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")
}
示例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
}
}
示例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
}
示例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
}
示例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")
}
}