當前位置: 首頁>>代碼示例>>Golang>>正文


Golang viper.GetString函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。