• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang viper.GetStringSlice函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/spf13/viper.GetStringSlice函数的典型用法代码示例。如果您正苦于以下问题:Golang GetStringSlice函数的具体用法?Golang GetStringSlice怎么用?Golang GetStringSlice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetStringSlice函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: setupMiddleware

func setupMiddleware() []http.Handler {
	return []http.Handler{
		adaptors.HandlerFromNegroni(cors.New(cors.Options{
			AllowedOrigins:   viper.GetStringSlice("cors.allowed_origins"),
			AllowedMethods:   viper.GetStringSlice("cors.allowed_methods"),
			AllowCredentials: viper.GetBool("cors.allow_credentials"),
		})),
		adaptors.HandlerFromNegroni(negroni.HandlerFunc(secure.New(secure.Options{
			AllowedHosts:            []string{},
			SSLRedirect:             false,
			SSLTemporaryRedirect:    false,
			SSLHost:                 "",
			SSLProxyHeaders:         map[string]string{},
			STSSeconds:              0,
			STSIncludeSubdomains:    false,
			STSPreload:              false,
			ForceSTSHeader:          false,
			FrameDeny:               false,
			CustomFrameOptionsValue: "",
			ContentTypeNosniff:      false,
			BrowserXssFilter:        false,
			ContentSecurityPolicy:   "",
			IsDevelopment:           viper.GetString("environment") == "development",
		}).HandlerFuncWithNext)),
	}
}
开发者ID:MustWin,项目名称:go-base,代码行数:26,代码来源:main.go


示例2: main

func main() {
	pflag.Parse()

	viper.SetConfigName("config")
	viper.AddConfigPath(".")

	if debug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	if err := viper.ReadInConfig(); err != nil {
		logrus.Fatal(err)
	}

	nick := viper.GetString("twitch.nick")
	pass := viper.GetString("twitch.pass")
	channels := viper.GetStringSlice("twitch.join")
	dbFilename := viper.GetString("database.filename")
	superusers := viper.GetStringSlice("permissions.superusers")

	bot := bot.NewBot(nick, pass, channels, dbFilename, superusers)
	if err := bot.Start(); err != nil {
		logrus.Fatal(err)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	<-c
	fmt.Print("\r\r\b")

	if err := bot.Stop(); err != nil {
		logrus.Fatal(err)
	}
}
开发者ID:jakebailey,项目名称:botzik,代码行数:34,代码来源:main.go


示例3: GetStringSlice

// GetStringSlice returns a config value as a string slice.
func (c *LiveConfig) GetStringSlice(ns, key string) []string {
	if ns == NSRoot {
		return viper.GetStringSlice(key)
	}

	nskey := fmt.Sprintf("%s-%s", ns, key)
	return viper.GetStringSlice(nskey)
}
开发者ID:neurodrone,项目名称:doit,代码行数:9,代码来源:doit.go


示例4: Show

func Show(cmd *cobra.Command, identities []string) {
	if len(identities) == 0 {
		fmt.Printf("Please provide at least one identity to show")
		return
	}

	s := state.NewState(viper.GetStringSlice("etc.hosts"))

	fmt.Printf("Found %d identities\n", len(identities))

	for _, id := range identities {
		identity, err := s.LoadIdentity(id)
		if err != nil {
			fmt.Printf("Failed to load identity %s: %s", id, err)
		}
		if identity == nil {
			fmt.Printf("Invalid identity %s", id)
			continue
		}

		fmt.Print("\n")
		fmt.Printf("Id: %s\n", identity.Id)
		fmt.Printf("Is Valid: %t\n", identity.IsValid())
		fmt.Printf("Is Signed: %t\n", identity.IsSigned())
		fmt.Printf("Has key: %t\n", identity.Key != nil)
		fmt.Printf("Fingerprint: % x\n", identity.Fingerprint())
		fmt.Printf("Serial Number: %d\n", identity.Certificate.SerialNumber)
		fmt.Printf("Created: %s\n", identity.Certificate.NotBefore)
		fmt.Printf("Expires: %s\n", identity.Certificate.NotAfter)
	}
}
开发者ID:borgstrom,项目名称:reeve,代码行数:31,代码来源:identites.go


示例5: isNonProcessablePath

func isNonProcessablePath(filePath string) bool {
	base := filepath.Base(filePath)
	if base[0] == '.' {
		return true
	}

	if base[0] == '#' {
		return true
	}

	if base[len(base)-1] == '~' {
		return true
	}

	ignoreFiles := viper.GetStringSlice("IgnoreFiles")
	if len(ignoreFiles) > 0 {
		for _, ignorePattern := range ignoreFiles {
			match, err := regexp.MatchString(ignorePattern, filePath)
			if err != nil {
				helpers.DistinctErrorLog.Printf("Invalid regexp '%s' in ignoreFiles: %s", ignorePattern, err)
				return false
			} else if match {
				return true
			}
		}
	}
	return false
}
开发者ID:yanwushuang,项目名称:pango,代码行数:28,代码来源:filesystem.go


示例6: main

func main() {
	flag.Parse() // Scan the arguments list
	InitializeConfig()
	graphite := fmt.Sprintf("%s%s%s", viper.GetString("graphite.host"), ":", viper.GetString("graphite.port"))
	prefix := fmt.Sprintf("%s", viper.GetString("graphite.prefix"))

	if *versionFlag {
		fmt.Println("cnm2g: Cn=monitor to Graphite")
		fmt.Println("Version:", APP_VERSION)
		fmt.Println("Config File >>>", viper.ConfigFileUsed())
		fmt.Println("Graphite >>>", graphite)
		fmt.Println("Prefix >>>", prefix)
		return
	}
	ldapmap := viper.GetStringMap("ldap")
	dnmap := viper.GetStringMap("dn")
	for ldap, _ := range ldapmap {
		ldapuri := viper.GetString(fmt.Sprintf("ldap.%s.uri", ldap))
		ldapuser := viper.GetString(fmt.Sprintf("ldap.%s.user", ldap))
		ldappass := viper.GetString(fmt.Sprintf("ldap.%s.pass", ldap))
		for dn, _ := range dnmap {
			prefixldap := fmt.Sprintf("%s.%s.%s", prefix, ldap, dn)
			data := viper.GetStringSlice(fmt.Sprintf("dn.%s.data", dn))
			basedn := viper.GetString(fmt.Sprintf("dn.%s.dn", dn))
			ldapresult := FetchData(ldapuri, ldapuser, ldappass, basedn, "(objectclass=*)", data)
			if DEBUG {
				ShowData(graphite, prefixldap, ldapresult)
			} else {
				SentData(graphite, prefixldap, ldapresult)
			}
		}
	}
}
开发者ID:gauthierc,项目名称:cnmonitor2graphite,代码行数:33,代码来源:main.go


示例7: loadConfig

func loadConfig() {
	stormpath.InitLog()

	viper.SetConfigType("yaml")
	viper.AutomaticEnv()

	//Load bundled default config
	defaultConfig, err := Asset("config/web.stormpath.yaml")
	if err != nil {
		stormpath.Logger.Panicf("[ERROR] Couldn't load default bundle configuration: %s", err)
	}

	viper.ReadConfig(bytes.NewBuffer(defaultConfig))

	//Merge users custom configuration
	viper.SetConfigFile("stormpath.yaml")
	viper.AddConfigPath("~/.stormpath/")
	viper.AddConfigPath(".")
	err = viper.MergeInConfig()
	if err != nil {
		stormpath.Logger.Println("[WARN] User didn't provide custom configuration")
	}

	Config.Produces = viper.GetStringSlice("stormpath.web.produces")
	Config.BasePath = viper.GetString("stormpath.web.basePath")

	loadSocialConfig()
	loadCookiesConfig()
	loadEndpointsConfig()
	loadOAuth2Config()
}
开发者ID:jxstanford,项目名称:stormpath-sdk-go,代码行数:31,代码来源:config.go


示例8: IsAdmin

// IsAdmin checks whether a particular Mumble user is a MumbleDJ admin.
// Returns true if the user is an admin, and false otherwise.
func (dj *MumbleDJ) IsAdmin(user *gumble.User) bool {
	for _, admin := range viper.GetStringSlice("admins.names") {
		if user.Name == admin {
			return true
		}
	}
	return false
}
开发者ID:matthieugrieger,项目名称:mumbledj,代码行数:10,代码来源:mumbledj.go


示例9: runCrossbuild

func runCrossbuild() {
	defer shell.ErrExit()
	shell.Tee = os.Stdout

	if viper.GetBool("verbose") {
		shell.Trace = true
	}

	var (
		goVersion        = viper.GetString("go")
		repoPath         = viper.GetString("repository.path")
		mainPlatforms    = viper.GetStringSlice("crossbuild.platforms.main")
		ARMPlatforms     = viper.GetStringSlice("crossbuild.platforms.arm")
		powerPCPlatforms = viper.GetStringSlice("crossbuild.platforms.powerpc")
		MIPSPlatforms    = viper.GetStringSlice("crossbuild.platforms.mips")

		dockerMainBuilderImage    = fmt.Sprintf("%s:%s-main", dockerBuilderImageName, goVersion)
		dockerARMBuilderImage     = fmt.Sprintf("%s:%s-arm", dockerBuilderImageName, goVersion)
		dockerPowerPCBuilderImage = fmt.Sprintf("%s:%s-powerpc", dockerBuilderImageName, goVersion)
		dockerMIPSBuilderImage    = fmt.Sprintf("%s:%s-mips", dockerBuilderImageName, goVersion)
	)

	if mainPlatformsParam := strings.Join(mainPlatforms[:], " "); mainPlatformsParam != "" {
		fmt.Println("> running the main builder docker image")
		sh("docker run --rm -t -v $PWD:/app",
			dockerMainBuilderImage, "-i", repoPath, "-p", q(mainPlatformsParam))
	}

	if ARMPlatformsParam := strings.Join(ARMPlatforms[:], " "); ARMPlatformsParam != "" {
		fmt.Println("> running the ARM builder docker image")
		sh("docker run --rm -t -v $PWD:/app",
			dockerARMBuilderImage, "-i", repoPath, "-p", q(ARMPlatformsParam))
	}

	if powerPCPlatformsParam := strings.Join(powerPCPlatforms[:], " "); powerPCPlatformsParam != "" {
		fmt.Println("> running the PowerPC builder docker image")
		sh("docker run --rm -t -v $PWD:/app",
			dockerPowerPCBuilderImage, "-i", repoPath, "-p", q(powerPCPlatformsParam))
	}

	if MIPSPlatformsParam := strings.Join(MIPSPlatforms[:], " "); MIPSPlatformsParam != "" {
		fmt.Println("> running the MIPS builder docker image")
		sh("docker run --rm -t -v $PWD:/app",
			dockerMIPSBuilderImage, "-i", repoPath, "-p", q(MIPSPlatformsParam))
	}
}
开发者ID:sdurrheimer,项目名称:promu,代码行数:46,代码来源:crossbuild.go


示例10: ReadConfig

func ReadConfig(agent *AgentCommand) *Config {
	err := viper.ReadInConfig() // Find and read the config file
	if err != nil {             // Handle errors reading the config file
		logrus.Infof("No valid config found: %s \n Applying default values.", err)
	}

	tags := viper.GetStringMapString("tags")
	server := viper.GetBool("server")
	nodeName := viper.GetString("node_name")

	if server {
		tags["dkron_server"] = "true"
	}
	tags["dkron_version"] = agent.Version

	InitLogger(viper.GetString("log_level"), nodeName)

	return &Config{
		NodeName:        nodeName,
		BindAddr:        viper.GetString("bind_addr"),
		AdvertiseAddr:   viper.GetString("advertise_addr"),
		HTTPAddr:        viper.GetString("http_addr"),
		Discover:        viper.GetString("discover"),
		Backend:         viper.GetString("backend"),
		BackendMachines: viper.GetStringSlice("backend_machine"),
		Server:          server,
		Profile:         viper.GetString("profile"),
		StartJoin:       viper.GetStringSlice("join"),
		Tags:            tags,
		Keyspace:        viper.GetString("keyspace"),
		EncryptKey:      viper.GetString("encrypt"),
		UIDir:           viper.GetString("ui_dir"),
		RPCPort:         viper.GetInt("rpc_port"),

		MailHost:     viper.GetString("mail_host"),
		MailPort:     uint16(viper.GetInt("mail_port")),
		MailUsername: viper.GetString("mail_username"),
		MailPassword: viper.GetString("mail_password"),
		MailFrom:     viper.GetString("mail_from"),
		MailPayload:  viper.GetString("mail_payload"),

		WebhookURL:     viper.GetString("webhook_url"),
		WebhookPayload: viper.GetString("webhook_payload"),
		WebhookHeaders: viper.GetStringSlice("webhook_headers"),
	}
}
开发者ID:oldmantaiter,项目名称:dkron,代码行数:46,代码来源:config.go


示例11: CreateDB

func CreateDB() *BloomDatabase {
	return &BloomDatabase{
		viper.GetString("sqlConnStr"),
		viper.GetStringSlice("searchHosts"),
		nil,
		nil,
	}
}
开发者ID:untoldone,项目名称:bloomapi,代码行数:8,代码来源:bloomdb.go


示例12: getConfiguredFormFieldNames

func getConfiguredFormFieldNames(formName string) []string {
	configuredFields := viper.GetStringMapString("stormpath.web." + formName + ".form.fields")
	fieldOrder := viper.GetStringSlice("stormpath.web." + formName + ".form.fieldOrder")

	for fieldName := range configuredFields {
		if !contains(fieldOrder, fieldName) {
			fieldOrder = append(fieldOrder, fieldName)
		}
	}
	return fieldOrder
}
开发者ID:jxstanford,项目名称:stormpath-sdk-go,代码行数:11,代码来源:form.go


示例13: Configure

func (s *StaticServerList) Configure(namespace string) {
	if s.Namespace != "" {
		//TODO: use logging
		fmt.Errorf("%s already inited: %s", StaticFactoryKey, s.Namespace)
		return
	}
	s.Namespace = namespace
	serverConfigs := viper.GetStringSlice(s.GetServerKey())
	fmt.Printf("serverConfigs %+v\n", serverConfigs)
	s.Servers = serverConfigs
}
开发者ID:spencergibb,项目名称:go-nuvem,代码行数:11,代码来源:staticserverlist.go


示例14: initEnviron

func initEnviron() {
	if hostedZone == "" {
		hostedZone = viper.GetString("hosted_zone")
	}
	if checkID == "" {
		checkID = viper.GetString("check_id")
	}
	if len(domains) == 0 {
		domains = viper.GetStringSlice("domain")
	}
}
开发者ID:yano3,项目名称:collector,代码行数:11,代码来源:watch.go


示例15: assertRegistry

func assertRegistry(t *testing.T, registry Registry) []string {
	registry.Register(util.Instance{Id: "1", Host: "127.0.0.1", Port: 8080})
	registry.Register(util.Instance{Id: "2", Host: "localhost", Port: 9080})

	servers := viper.GetStringSlice(util.GetStaticRegistryKey(registry))

	require.NotNil(t, servers, "servers was nil")
	require.Equal(t, 2, len(servers), "wrong # of servers")

	return servers
}
开发者ID:spencergibb,项目名称:go-nuvem,代码行数:11,代码来源:staticregistry_test.go


示例16: Configure

func (s *StaticDiscovery) Configure(namespace string) {
	if s.Namespace != "" {
		//TODO: use logging
		fmt.Errorf("%s already inited: %s", StaticFactoryKey, s.Namespace)
		return
	}
	s.Namespace = namespace
	instances := viper.GetStringSlice(util.GetStaticRegistryKey(s))
	fmt.Printf("instances %+v\n", instances)
	s.Instances = instances
}
开发者ID:spencergibb,项目名称:go-nuvem,代码行数:11,代码来源:staticdiscovery.go


示例17: loadConfig

func (ui *tatui) loadConfig() {
	internal.ReadConfig()
	filters := viper.GetStringSlice("filters")

	// no range to keep order
	for index := 0; index < len(filters); index++ {
		filter := filters[index]
		tuples := strings.Split(filter, " ")
		if len(tuples) <= 2 {
			continue
		}
		topic := tuples[1]
		if _, ok := ui.currentFilterMessages[topic]; !ok {
			ui.currentFilterMessages[topic] = make(map[int]*tat.MessageCriteria)
			ui.currentFilterMessagesText[topic] = make(map[int]string)
		}
		c, criteriaText := ui.prepareFilterMessages(strings.Join(tuples[2:], " "), tuples[0], topic)
		ui.currentFilterMessages[topic][len(ui.currentFilterMessages[topic])] = c
		ui.currentFilterMessagesText[topic][len(ui.currentFilterMessagesText[topic])] = criteriaText
	}

	commands := viper.GetStringSlice("commands")
	// no range to keep order
	for index := 0; index < len(commands); index++ {
		commandsOnTopic := commands[index]
		tuples := strings.Split(strings.TrimSpace(commandsOnTopic), " ")
		if len(tuples) <= 1 {
			continue
		}
		topic := tuples[0]
		ui.uiTopicCommands[topic] = commandsOnTopic[len(topic):]
	}

	var conf config.TemplateJSONType
	err := viper.Unmarshal(&conf)
	if err != nil {
		internal.Exit("unable to decode confif file, err: %v", err)
	}

	ui.hooks = conf.Hooks
}
开发者ID:ovh,项目名称:tatcli,代码行数:41,代码来源:config.go


示例18: TestViperGetStringOrFail

func TestViperGetStringOrFail(t *testing.T) {
	assert := assert.New(t)
	viper.SetConfigFile("../.ayi.example.yml")
	err := viper.ReadInConfig()
	assert.Nil(err)
	s, err := ViperGetStringOrFail("scripts.mie")
	assert.Equal("echo mie", s)
	_, err = ViperGetStringOrFail("scripts.qian")
	assert.NotNil(err)
	ss := viper.GetStringSlice("scripts.qian")
	assert.Equal(2, len(ss))
}
开发者ID:dyweb,项目名称:Ayi,代码行数:12,代码来源:viper_test.go


示例19: runTarball

func runTarball(binariesLocation string) {
	defer shell.ErrExit()
	shell.Tee = os.Stdout

	if viper.GetBool("verbose") {
		shell.Trace = true
	}

	info := NewProjectInfo()

	var (
		prefix = viper.GetString("tarball.prefix")
		tmpDir = ".release"
		goos   = envOr("GOOS", goos)
		goarch = envOr("GOARCH", goarch)
		name   = fmt.Sprintf("%s-%s.%s-%s", info.Name, info.Version, goos, goarch)

		binaries []Binary
		ext      string
	)

	if goos == "windows" {
		ext = ".exe"
	}

	dir := filepath.Join(tmpDir, name)

	if err := os.MkdirAll(dir, 0777); err != nil {
		fatalMsg(err, "Failed to create directory")
	}
	defer sh("rm -rf", tmpDir)

	projectFiles := viper.GetStringSlice("tarball.files")
	for _, file := range projectFiles {
		sh("cp -a", file, dir)
	}

	err := viper.UnmarshalKey("build.binaries", &binaries)
	fatalMsg(err, "Failed to Unmashal binaries :")

	for _, binary := range binaries {
		binaryName := fmt.Sprintf("%s%s", binary.Name, ext)
		sh("cp -a", shell.Path(binariesLocation, binaryName), dir)
	}

	if !fileExists(prefix) {
		os.Mkdir(prefix, 0777)
	}

	tar := fmt.Sprintf("%s.tar.gz", name)
	fmt.Println(" >  ", tar)
	sh("tar zcf", shell.Path(prefix, tar), "-C", tmpDir, name)
}
开发者ID:sdurrheimer,项目名称:promu,代码行数:53,代码来源:tarball.go


示例20: Sign

func Sign(cmd *cobra.Command, identities []string) {
	if len(identities) == 0 {
		fmt.Printf("Please provide at least one identity to sign")
		return
	}

	s := state.NewState(viper.GetStringSlice("etc.hosts"))

	authority, err := s.LoadAuthority()
	if err != nil {
		fmt.Printf("Failed to load authority: %s", err)
	}

	for _, id := range identities {
		identity, err := s.LoadIdentity(id)
		if err != nil {
			fmt.Printf("Failed to load identity %s: %s", id, err)
		}
		if identity == nil {
			fmt.Printf("Invalid identity: %s", id)
			continue
		}

		if identity.Request == nil {
			fmt.Printf("The identity, %s, does not have a request attached to it", id)
			continue
		}

		if identity.Certificate != nil {
			fmt.Printf("The identity, %s, already has a certificate attached to it.", id)
			continue
		}

		cert, err := authority.Sign(identity.Request)
		if err != nil {
			fmt.Printf("Failed to sign the request for %s: %s", id, err)
		}

		if err = s.StoreAuthoritySerial(authority); err != nil {
			fmt.Printf("Failed to store the authority serial number for %s: %s", id, err)
		}

		identity.Certificate = cert
		if err = s.StoreIdentity(identity); err != nil {
			fmt.Printf("Failed to store identity after signing request for %s: %s", id, err)
		}

		s.RemoveIdentityFromPending(identity)

		fmt.Printf("Signed %s", id)
	}
}
开发者ID:borgstrom,项目名称:reeve,代码行数:52,代码来源:identites.go



注:本文中的github.com/spf13/viper.GetStringSlice函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang viper.IsSet函数代码示例发布时间:2022-05-28
下一篇:
Golang viper.GetStringMapString函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap