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


Golang viper.GetStringSlice函數代碼示例

本文整理匯總了Golang中github.com/spf13/viper.GetStringSlice函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetStringSlice函數的具體用法?Golang GetStringSlice怎麽用?Golang GetStringSlice使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetStringSlice函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


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