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


Golang viper.Viper類代碼示例

本文整理匯總了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
}
開發者ID:brunocascio,項目名稱:centrifugo,代碼行數:15,代碼來源:config.go

示例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
}
開發者ID:rvaughan,項目名稱:centrifugo,代碼行數:24,代碼來源:config.go

示例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
}
開發者ID:rvaughan,項目名稱:centrifugo,代碼行數:44,代碼來源:config.go


注:本文中的github.com/centrifugal/centrifugo/Godeps/_workspace/src/github.com/spf13/viper.Viper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。