本文整理汇总了Golang中github.com/centrifugal/centrifugo/Godeps/_workspace/src/github.com/spf13/viper.GetString函数的典型用法代码示例。如果您正苦于以下问题:Golang GetString函数的具体用法?Golang GetString怎么用?Golang GetString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetString函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: setupLogging
func setupLogging() {
logLevel, ok := logger.LevelMatches[strings.ToUpper(viper.GetString("log_level"))]
if !ok {
logLevel = logger.LevelInfo
}
logger.SetLogThreshold(logLevel)
logger.SetStdoutThreshold(logLevel)
if viper.IsSet("log_file") && viper.GetString("log_file") != "" {
logger.SetLogFile(viper.GetString("log_file"))
// do not log into stdout when log file provided
logger.SetStdoutThreshold(logger.LevelNone)
}
}
开发者ID:xuanhan863,项目名称:centrifugo,代码行数:14,代码来源:main.go
示例2: getApplicationName
// getApplicationName returns a name for this node. If no name provided
// in configuration then it constructs node name based on hostname and port
func getApplicationName() string {
name := viper.GetString("name")
if name != "" {
return name
}
port := viper.GetString("port")
var hostname string
hostname, err := os.Hostname()
if err != nil {
logger.ERROR.Println(err)
hostname = "?"
}
return hostname + "_" + port
}
开发者ID:brunocascio,项目名称:centrifugo,代码行数:16,代码来源:config.go
示例3: newConfig
func newConfig() *libcentrifugo.Config {
cfg := &libcentrifugo.Config{}
cfg.Version = VERSION
cfg.Name = getApplicationName()
cfg.WebPassword = viper.GetString("web_password")
cfg.WebSecret = viper.GetString("web_secret")
cfg.ChannelPrefix = viper.GetString("channel_prefix")
cfg.AdminChannel = libcentrifugo.ChannelID(cfg.ChannelPrefix + "." + "admin")
cfg.ControlChannel = libcentrifugo.ChannelID(cfg.ChannelPrefix + "." + "control")
cfg.MaxChannelLength = viper.GetInt("max_channel_length")
cfg.NodePingInterval = int64(viper.GetInt("node_ping_interval"))
cfg.NodeInfoCleanInterval = cfg.NodePingInterval * 3
cfg.NodeInfoMaxDelay = cfg.NodePingInterval*2 + 1
cfg.PresencePingInterval = int64(viper.GetInt("presence_ping_interval"))
cfg.PresenceExpireInterval = int64(viper.GetInt("presence_expire_interval"))
cfg.MessageSendTimeout = int64(viper.GetInt("message_send_timeout"))
cfg.PrivateChannelPrefix = viper.GetString("private_channel_prefix")
cfg.NamespaceChannelBoundary = viper.GetString("namespace_channel_boundary")
cfg.UserChannelBoundary = viper.GetString("user_channel_boundary")
cfg.UserChannelSeparator = viper.GetString("user_channel_separator")
cfg.ClientChannelBoundary = viper.GetString("client_channel_boundary")
cfg.ExpiredConnectionCloseDelay = int64(viper.GetInt("expired_connection_close_delay"))
cfg.Insecure = viper.GetBool("insecure")
return cfg
}
开发者ID:rvaughan,项目名称:centrifugo,代码行数:25,代码来源:config.go
示例4: newConfig
// newConfig creates new libcentrifugo.Config using viper.
func newConfig() *libcentrifugo.Config {
cfg := &libcentrifugo.Config{}
cfg.Version = VERSION
cfg.Name = getApplicationName()
cfg.Debug = viper.GetBool("debug")
cfg.Web = viper.GetBool("web")
cfg.WebPassword = viper.GetString("web_password")
cfg.WebSecret = viper.GetString("web_secret")
cfg.ChannelPrefix = viper.GetString("channel_prefix")
cfg.AdminChannel = libcentrifugo.ChannelID(cfg.ChannelPrefix + "." + "admin")
cfg.ControlChannel = libcentrifugo.ChannelID(cfg.ChannelPrefix + "." + "control")
cfg.MaxChannelLength = viper.GetInt("max_channel_length")
cfg.PingInterval = time.Duration(viper.GetInt("ping_interval")) * time.Second
cfg.NodePingInterval = time.Duration(viper.GetInt("node_ping_interval")) * time.Second
cfg.NodeInfoCleanInterval = cfg.NodePingInterval * 3
cfg.NodeInfoMaxDelay = cfg.NodePingInterval*2 + 1*time.Second
cfg.NodeMetricsInterval = time.Duration(viper.GetInt("node_metrics_interval")) * time.Second
cfg.PresencePingInterval = time.Duration(viper.GetInt("presence_ping_interval")) * time.Second
cfg.PresenceExpireInterval = time.Duration(viper.GetInt("presence_expire_interval")) * time.Second
cfg.MessageSendTimeout = time.Duration(viper.GetInt("message_send_timeout")) * time.Second
cfg.PrivateChannelPrefix = viper.GetString("private_channel_prefix")
cfg.NamespaceChannelBoundary = viper.GetString("namespace_channel_boundary")
cfg.UserChannelBoundary = viper.GetString("user_channel_boundary")
cfg.UserChannelSeparator = viper.GetString("user_channel_separator")
cfg.ClientChannelBoundary = viper.GetString("client_channel_boundary")
cfg.ExpiredConnectionCloseDelay = time.Duration(viper.GetInt("expired_connection_close_delay")) * time.Second
cfg.StaleConnectionCloseDelay = time.Duration(viper.GetInt("stale_connection_close_delay")) * time.Second
cfg.ClientRequestMaxSize = viper.GetInt("client_request_max_size")
cfg.ClientQueueMaxSize = viper.GetInt("client_queue_max_size")
cfg.ClientQueueInitialCapacity = viper.GetInt("client_queue_initial_capacity")
cfg.ClientChannelLimit = viper.GetInt("client_channel_limit")
cfg.Insecure = viper.GetBool("insecure")
cfg.InsecureAPI = viper.GetBool("insecure_api")
cfg.InsecureWeb = viper.GetBool("insecure_web")
cfg.Secret = viper.GetString("secret")
cfg.ConnLifetime = int64(viper.GetInt("connection_lifetime"))
cfg.Watch = viper.GetBool("watch")
cfg.Publish = viper.GetBool("publish")
cfg.Anonymous = viper.GetBool("anonymous")
cfg.Presence = viper.GetBool("presence")
cfg.JoinLeave = viper.GetBool("join_leave")
cfg.HistorySize = viper.GetInt("history_size")
cfg.HistoryLifetime = viper.GetInt("history_lifetime")
cfg.HistoryDropInactive = viper.GetBool("history_drop_inactive")
cfg.Recover = viper.GetBool("recover")
cfg.Namespaces = namespacesFromConfig(nil)
return cfg
}
开发者ID:axmadjon,项目名称:centrifugo,代码行数:52,代码来源:config.go
示例5: 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
}
开发者ID:rvaughan,项目名称:centrifugo,代码行数:44,代码来源:config.go
示例6: Main
//.........这里部分代码省略.........
}
setupLogging()
if os.Getenv("GOMAXPROCS") == "" {
if viper.IsSet("gomaxprocs") && viper.GetInt("gomaxprocs") > 0 {
runtime.GOMAXPROCS(viper.GetInt("gomaxprocs"))
} else {
runtime.GOMAXPROCS(runtime.NumCPU())
}
}
logger.INFO.Println("GOMAXPROCS:", runtime.GOMAXPROCS(0))
c := newConfig()
err = c.Validate()
if err != nil {
logger.FATAL.Fatalln(err)
}
app, err := libcentrifugo.NewApplication(c)
if err != nil {
logger.FATAL.Fatalln(err)
}
if c.Insecure {
logger.WARN.Println("application running in INSECURE client mode")
}
if c.InsecureAPI {
logger.WARN.Println("application running in INSECURE API mode")
}
var e libcentrifugo.Engine
switch viper.GetString("engine") {
case "memory":
e = libcentrifugo.NewMemoryEngine(app)
case "redis":
e = libcentrifugo.NewRedisEngine(
app,
viper.GetString("redis_host"),
viper.GetString("redis_port"),
viper.GetString("redis_password"),
viper.GetString("redis_db"),
viper.GetString("redis_url"),
viper.GetBool("redis_api"),
viper.GetInt("redis_pool"),
)
default:
logger.FATAL.Fatalln("Unknown engine: " + viper.GetString("engine"))
}
logger.INFO.Println("Engine:", viper.GetString("engine"))
logger.DEBUG.Printf("%v\n", viper.AllSettings())
logger.INFO.Println("Use SSL:", viper.GetBool("ssl"))
if viper.GetBool("ssl") {
if viper.GetString("ssl_cert") == "" {
logger.FATAL.Println("No SSL certificate provided")
os.Exit(1)
}
if viper.GetString("ssl_key") == "" {
logger.FATAL.Println("No SSL certificate key provided")
os.Exit(1)
}
}
app.SetEngine(e)
err = app.Run()
开发者ID:xuanhan863,项目名称:centrifugo,代码行数:67,代码来源:main.go
示例7: Main
//.........这里部分代码省略.........
if err != nil {
logger.FATAL.Fatalln(err)
}
viper.SetConfigFile(configFile)
err = viper.ReadInConfig()
if err != nil {
logger.FATAL.Fatalln("Unable to locate config file")
}
setupLogging()
if os.Getenv("GOMAXPROCS") == "" {
if viper.IsSet("gomaxprocs") && viper.GetInt("gomaxprocs") > 0 {
runtime.GOMAXPROCS(viper.GetInt("gomaxprocs"))
} else {
runtime.GOMAXPROCS(runtime.NumCPU())
}
}
logger.INFO.Println("GOMAXPROCS set to", runtime.GOMAXPROCS(0))
logger.INFO.Println("Using config file:", viper.ConfigFileUsed())
c := newConfig()
s := structureFromConfig(nil)
app, err := libcentrifugo.NewApplication(c)
if err != nil {
logger.FATAL.Fatalln(err)
}
app.SetStructure(s)
var e libcentrifugo.Engine
switch viper.GetString("engine") {
case "memory":
e = libcentrifugo.NewMemoryEngine(app)
case "redis":
e = libcentrifugo.NewRedisEngine(
app,
viper.GetString("redis_host"),
viper.GetString("redis_port"),
viper.GetString("redis_password"),
viper.GetString("redis_db"),
viper.GetString("redis_url"),
viper.GetBool("redis_api"),
viper.GetInt("redis_pool"),
)
default:
logger.FATAL.Fatalln("unknown engine: " + viper.GetString("engine"))
}
logger.INFO.Println("Engine:", viper.GetString("engine"))
logger.DEBUG.Printf("%v\n", viper.AllSettings())
logger.INFO.Println("Use SSL:", viper.GetBool("ssl"))
if viper.GetBool("ssl") {
if viper.GetString("ssl_cert") == "" {
logger.FATAL.Println("No SSL certificate provided")
os.Exit(1)
}
if viper.GetString("ssl_key") == "" {
logger.FATAL.Println("No SSL certificate key provided")
os.Exit(1)
}
}
app.SetEngine(e)
开发者ID:rvaughan,项目名称:centrifugo,代码行数:66,代码来源:main.go
注:本文中的github.com/centrifugal/centrifugo/Godeps/_workspace/src/github.com/spf13/viper.GetString函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论