本文整理匯總了Golang中github.com/centrifugal/centrifugo/Godeps/_workspace/src/github.com/spf13/viper.Viper類的典型用法代碼示例。如果您正苦於以下問題:Golang Viper類的具體用法?Golang Viper怎麽用?Golang Viper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Viper類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: namespacesFromConfig
func namespacesFromConfig(v *viper.Viper) []libcentrifugo.Namespace {
// TODO: as viper does not have exported global config instance
// we need to use nil when application wants to use global viper
// config - this must be improved using our own global viper instance
ns := []libcentrifugo.Namespace{}
if !viper.IsSet("namespaces") {
return ns
}
if v == nil {
viper.MarshalKey("namespaces", &ns)
} else {
v.MarshalKey("namespaces", &ns)
}
return ns
}
示例2: structureFromConfig
func structureFromConfig(v *viper.Viper) *libcentrifugo.Structure {
// TODO: as viper does not have exported global config instance
// we need to use nil when application wants to use global viper
// config - this must be improved using our own global viper instance
var pl []libcentrifugo.Project
if v == nil {
viper.MarshalKey("projects", &pl)
} else {
v.MarshalKey("projects", &pl)
}
// top level project configuration
p, exists := getGlobalProject(v)
if exists {
// add global project to project list
pl = append([]libcentrifugo.Project{*p}, pl...)
}
s := libcentrifugo.NewStructure(pl)
return s
}
示例3: getGlobalProject
func getGlobalProject(v *viper.Viper) (*libcentrifugo.Project, bool) {
p := &libcentrifugo.Project{}
// TODO: the same as for structureFromConfig function
if v == nil {
if !viper.IsSet("project_name") || viper.GetString("project_name") == "" {
return nil, false
}
p.Name = libcentrifugo.ProjectKey(viper.GetString("project_name"))
p.Secret = viper.GetString("project_secret")
p.ConnLifetime = int64(viper.GetInt("project_connection_lifetime"))
p.Anonymous = viper.GetBool("project_anonymous")
p.Watch = viper.GetBool("project_watch")
p.Publish = viper.GetBool("project_publish")
p.JoinLeave = viper.GetBool("project_join_leave")
p.Presence = viper.GetBool("project_presence")
p.HistorySize = int64(viper.GetInt("project_history_size"))
p.HistoryLifetime = int64(viper.GetInt("project_history_lifetime"))
} else {
if !v.IsSet("project_name") || v.GetString("project_name") == "" {
return nil, false
}
p.Name = libcentrifugo.ProjectKey(v.GetString("project_name"))
p.Secret = v.GetString("project_secret")
p.ConnLifetime = int64(v.GetInt("project_connection_lifetime"))
p.Anonymous = v.GetBool("project_anonymous")
p.Watch = v.GetBool("project_watch")
p.Publish = v.GetBool("project_publish")
p.JoinLeave = v.GetBool("project_join_leave")
p.Presence = v.GetBool("project_presence")
p.HistorySize = int64(v.GetInt("project_history_size"))
p.HistoryLifetime = int64(v.GetInt("project_history_lifetime"))
}
var nl []libcentrifugo.Namespace
if v == nil {
viper.MarshalKey("project_namespaces", &nl)
} else {
v.MarshalKey("project_namespaces", &nl)
}
p.Namespaces = nl
return p, true
}