本文整理汇总了Golang中github.com/spf13/viper.IsSet函数的典型用法代码示例。如果您正苦于以下问题:Golang IsSet函数的具体用法?Golang IsSet怎么用?Golang IsSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsSet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Init
// Init initializes the crypto layer. It load from viper the security level
// and the logging setting.
func Init() (err error) {
// Init security level
securityLevel := 256
if viper.IsSet("security.level") {
ovveride := viper.GetInt("security.level")
if ovveride != 0 {
securityLevel = ovveride
}
}
hashAlgorithm := "SHA3"
if viper.IsSet("security.hashAlgorithm") {
ovveride := viper.GetString("security.hashAlgorithm")
if ovveride != "" {
hashAlgorithm = ovveride
}
}
log.Debugf("Working at security level [%d]", securityLevel)
if err = primitives.InitSecurityLevel(hashAlgorithm, securityLevel); err != nil {
log.Errorf("Failed setting security level: [%s]", err)
return
}
return
}
开发者ID:srderson,项目名称:fabric,代码行数:29,代码来源:crypto_settings.go
示例2: parseDefaultPygmentsOpts
func parseDefaultPygmentsOpts() (map[string]string, error) {
options := make(map[string]string)
err := parseOptions(options, viper.GetString("PygmentsOptions"))
if err != nil {
return nil, err
}
if viper.IsSet("PygmentsStyle") {
options["style"] = viper.GetString("PygmentsStyle")
}
if viper.IsSet("PygmentsUseClasses") {
if viper.GetBool("PygmentsUseClasses") {
options["noclasses"] = "false"
} else {
options["noclasses"] = "true"
}
}
if _, ok := options["encoding"]; !ok {
options["encoding"] = "utf8"
}
return options, nil
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:27,代码来源:pygments.go
示例3: getLdflags
func getLdflags(info ProjectInfo) string {
if viper.IsSet("build.ldflags") {
var (
tmplOutput = new(bytes.Buffer)
fnMap = template.FuncMap{
"date": time.Now().UTC().Format,
"host": os.Hostname,
"user": UserFunc,
"goversion": runtime.Version,
"repoPath": RepoPathFunc,
}
ldflags = viper.GetString("build.ldflags")
)
tmpl, err := template.New("ldflags").Funcs(fnMap).Parse(ldflags)
fatalMsg(err, "Failed to parse ldflags text/template :")
err = tmpl.Execute(tmplOutput, info)
fatalMsg(err, "Failed to execute ldflags text/template :")
if goos != "darwin" {
tmplOutput.WriteString("-extldflags \"-static\"")
}
return tmplOutput.String()
}
return fmt.Sprintf("-X main.Version %s", info.Version)
}
开发者ID:sdurrheimer,项目名称:promu,代码行数:29,代码来源:build.go
示例4: watch
func watch() {
if !viper.IsSet("raven_dev") {
log.Fatal("Please specify a Raven device to connect to")
}
raven, err := goraven.Connect(viper.GetString("raven_dev"))
if err != nil {
log.Fatal(err)
}
defer raven.Close()
for {
notify, err := raven.Receive()
if err != nil {
log.Println(err)
}
switch t := notify.(type) {
case *goraven.ConnectionStatus:
log.Printf("Connection Status: %s", t.Status)
case *goraven.CurrentSummationDelivered:
pushCurrentSummationDelivered(t)
case *goraven.InstantaneousDemand:
pushInstantaneousDemand(t)
default:
}
}
}
开发者ID:dahenson,项目名称:energywatch,代码行数:29,代码来源:watch.go
示例5: Init
// Init initializes the crypto layer. It load from viper the security level
// and the logging setting.
func Init() (err error) {
// Init log
log.ExtraCalldepth++
level, err := logging.LogLevel(viper.GetString("logging.crypto"))
if err == nil {
// No error, use the setting
logging.SetLevel(level, "crypto")
log.Info("Log level recognized '%s', set to %s", viper.GetString("logging.crypto"),
logging.GetLevel("crypto"))
} else {
log.Warning("Log level not recognized '%s', defaulting to %s: %s", viper.GetString("logging.crypto"),
logging.GetLevel("crypto"), err)
}
// Init security level
securityLevel := 256
if viper.IsSet("security.level") {
ovveride := viper.GetInt("security.level")
if ovveride != 0 {
securityLevel = ovveride
}
}
log.Debug("Working at security level [%d]", securityLevel)
if err = conf.InitSecurityLevel(securityLevel); err != nil {
log.Debug("Failed setting security level: [%s]", err)
return
}
return
}
开发者ID:tanyakchoon,项目名称:obc-peer,代码行数:35,代码来源:crypto_settings.go
示例6: Execute
func (m *conduitServerService) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue
changes <- svc.Status{State: svc.StartPending}
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
if viper.IsSet("enable_long_polling") {
server.EnableLongPolling = viper.GetBool("enable_long_polling")
}
err := server.Start(viper.GetString("host"))
fmt.Println("Could not start server:", err)
loop:
for {
select {
case c := <-r:
switch c.Cmd {
case svc.Interrogate:
changes <- c.CurrentStatus
time.Sleep(100 * time.Millisecond)
changes <- c.CurrentStatus
case svc.Stop, svc.Shutdown:
break loop
default:
}
}
}
changes <- svc.Status{State: svc.StopPending}
return
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:27,代码来源:service.server.go
示例7: overwriteFlagsWithViperConfig
// overwriteFlagsWithViperConfig finds and writes values to flags using viper as input.
func overwriteFlagsWithViperConfig() {
viperFlagSetter := func(f *flag.Flag) {
if viper.IsSet(f.Name) {
f.Value.Set(viper.GetString(f.Name))
}
}
flag.VisitAll(viperFlagSetter)
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:9,代码来源:test_context.go
示例8: validityPeriodUpdateEnabled
func validityPeriodUpdateEnabled() bool {
// If the update of the validity period is enabled in the configuration file return the configured value
if viper.IsSet("pki.validity-period.update") {
return viper.GetBool("pki.validity-period.update")
}
// Validity period update is enabled by default if no configuration was specified.
return true
}
开发者ID:tenc,项目名称:obc-peer-pre-public,代码行数:9,代码来源:validity_period.go
示例9: validityPeriodVerificationEnabled
func validityPeriodVerificationEnabled() bool {
// If the verification of the validity period is enabled in the configuration file return the configured value
if viper.IsSet("peer.validator.validity-period.verification") {
return viper.GetBool("peer.validator.validity-period.verification")
}
// Validity period verification is enabled by default if no configuration was specified.
return true
}
开发者ID:yhjohn163,项目名称:obc-peer,代码行数:9,代码来源:validator_validity_period.go
示例10: deploySystemChaincodeEnabled
func deploySystemChaincodeEnabled() bool {
// If the deployment of system chaincode is enabled in the configuration file return the configured value
if viper.IsSet("ledger.blockchain.deploy-system-chaincode") {
return viper.GetBool("ledger.blockchain.deploy-system-chaincode")
}
// Deployment of system chaincode is enabled by default if no configuration was specified.
return true
}
开发者ID:butine,项目名称:research,代码行数:9,代码来源:genesis.go
示例11: TestViper
//TestViper try to use viper
func TestViper() {
viper.AddConfigPath("/home/xiaoju/goworkspace/goplayground/")
viper.SetConfigName("test")
viper.SetConfigType("toml")
err := viper.ReadInConfig()
if err != nil {
fmt.Println("read viper configure", err)
}
//
var x int
if viper.IsSet("logger.meta.other.xo") {
x = viper.GetInt("logger.meta.other.xo")
} else {
x = 8
}
if viper.IsSet("logger.meta.input") {
metaInput := viper.GetStringMap("logger.meta.input")
for k, v := range metaInput {
// if viper.IsSet("logger.meta.input." + k) {
// kv := viper.GetStringMapString("logger.meta.input." + k)
// for x, y := range kv {
// fmt.Println(x, y)
// }
// }
fmt.Println(k, v)
if value, ok := v.(map[string]string); ok {
for x, y := range value {
fmt.Println(x, y)
}
} else {
fmt.Println(ok)
}
}
}
// for k, v := range logConf["meta"]["input"] {
// fmt.Println(k, v)
// }
fmt.Println(x)
}
开发者ID:ambjlon,项目名称:goplayground,代码行数:44,代码来源:viper.go
示例12: NewApp
func NewApp(cnfFileName string) *App {
log.Printf("httpapi init, read config from: %s\n", cnfFileName)
app := &App{}
app.router = echo.New()
app.router.Use(middleware.Logger(), middleware.Recover())
app.router.Use(echoJsonCheckErrorMW())
app.router.Get("/vms", app.handleListVm)
app.router.Post("/vms/:alias", app.handleDownloadVm)
viper.SetConfigFile(cnfFileName)
err := viper.ReadInConfig()
//if config file exists and configs have been read successfully
if err == nil {
for _, cnfAlias := range []string{
"GOVC_URL",
"GOVC_USERNAME",
"GOVC_PASSWORD",
"GOVC_CERTIFICATE",
"GOVC_PRIVATE_KEY",
"GOVC_INSECURE",
"GOVC_PERSIST_SESSION",
"GOVC_MIN_API_VERSION",
} {
//rewrite only if not set in env scope
if viper.IsSet(cnfAlias) && os.Getenv(cnfAlias) == "" {
//log.Printf("write to env: %s=%s\n", cnfAlias, viper.GetString(cnfAlias))
os.Setenv(cnfAlias, viper.GetString(cnfAlias))
}
}
if viper.IsSet("vm-path") {
app.vmPath = viper.GetString("vm-path")
//log.Printf("vm path for host: %s\n", app.vmPath)
}
} else {
log.Fatalf("%s\nThis application need config.json with vm-path key and path to VM on host machine\n", err)
}
return app
}
开发者ID:arbrix,项目名称:govm,代码行数:40,代码来源:govm.go
示例13: InitializeConfig
// InitializeConfig loads our configuration using Viper package.
func InitializeConfig() {
// Set config file
viper.SetConfigName("config")
// Add config path
viper.AddConfigPath("$HOME/.sharptv")
// Read in the config
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
// Load default settings
viper.SetDefault("debug", false)
viper.SetEnvPrefix("gosharptv") // will be uppercased automatically
viper.BindEnv("debug")
viper.BindEnv("ip")
viper.BindEnv("port")
// Do some flag handling and any complicated config logic
if !viper.IsSet("ip") || !viper.IsSet("port") {
fmt.Println("Configuration error. Both IP and PORT must be set via either config, environment, or flags.")
os.Exit(1)
}
// TODO --implement the use of this data in the input command
inputLabelMap = make(map[string]int)
inputNames := []string{"input1", "input2", "input3", "input4", "input5", "input6", "input7", "input8"}
for i, v := range inputNames {
if viper.IsSet(v) {
inputname := viper.GetString(v)
inputLabelMap[inputname] = i + 1
}
}
}
开发者ID:golliher,项目名称:go-sharptv,代码行数:40,代码来源:sharptv.go
示例14: whichLicense
func whichLicense() string {
// if explicitly flagged, use that
if userLicense != "" {
return matchLicense(userLicense)
}
// if already present in the project, use that
// TODO: Inspect project for existing license
// default to viper's setting
if viper.IsSet("license.header") || viper.IsSet("license.text") {
if custom, ok := Licenses["custom"]; ok {
custom.Header = viper.GetString("license.header")
custom.Text = viper.GetString("license.text")
Licenses["custom"] = custom
return "custom"
}
}
return matchLicense(viper.GetString("license"))
}
开发者ID:ContiGuy,项目名称:conti-gui,代码行数:22,代码来源:helpers.go
示例15: 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:rohan1790,项目名称:centrifugo,代码行数:14,代码来源:main.go
示例16: loadConfigs
func loadConfigs() {
genesisLogger.Info("Loading configurations...")
genesis = viper.GetStringMap("ledger.blockchain.genesisBlock")
mode = viper.GetString("chaincode.chaincoderunmode")
genesisLogger.Info("Configurations loaded: genesis=%s, mode=[%s], deploySystemChaincodeEnabled=[%t]",
genesis, mode, deploySystemChaincodeEnabled)
if viper.IsSet("ledger.blockchain.deploy-system-chaincode") {
// If the deployment of system chaincode is enabled in the configuration file return the configured value
deploySystemChaincodeEnabled = viper.GetBool("ledger.blockchain.deploy-system-chaincode")
} else {
// Deployment of system chaincode is enabled by default if no configuration was specified.
deploySystemChaincodeEnabled = true
}
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:14,代码来源:config.go
示例17: 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:rohan1790,项目名称:centrifugo,代码行数:44,代码来源:config.go
示例18: init
func (conf *configuration) init() error {
conf.configurationPathProperty = "peer.fileSystemPath"
conf.ecaPAddressProperty = "peer.pki.eca.paddr"
conf.tcaPAddressProperty = "peer.pki.tca.paddr"
conf.tlscaPAddressProperty = "peer.pki.tlsca.paddr"
// Check mandatory fields
if err := conf.checkProperty(conf.configurationPathProperty); err != nil {
return err
}
if err := conf.checkProperty(conf.ecaPAddressProperty); err != nil {
return err
}
if err := conf.checkProperty(conf.tcaPAddressProperty); err != nil {
return err
}
if err := conf.checkProperty(conf.tlscaPAddressProperty); err != nil {
return err
}
// Set configuration path
conf.configurationPath = filepath.Join(
viper.GetString(conf.configurationPathProperty),
"crypto", conf.prefix, conf.name,
)
// Set ks path
conf.keystorePath = filepath.Join(conf.configurationPath, "ks")
// Set raws path
conf.rawsPath = filepath.Join(conf.keystorePath, "raw")
// Set TLS host override
conf.tlsServerName = "tlsca"
if viper.IsSet("peer.pki.tls.server-host-override") {
ovveride := viper.GetString("peer.pki.tls.server-host-override")
if ovveride != "" {
conf.tlsServerName = ovveride
}
}
return nil
}
开发者ID:butine,项目名称:research,代码行数:43,代码来源:node_conf.go
示例19: init
func init() {
viper.SetDefault("port", 8080)
viper.SetDefault("min_passwd_len", 8)
viper.SetDefault("pgp_sign", false)
viper.SetDefault("smtp_host", "localhost")
viper.SetDefault("smtp_port", 25)
viper.SetDefault("email_link_base", "http://localhost")
viper.SetDefault("email_from", "[email protected]")
viper.SetDefault("email_prefix", "mokey")
viper.SetDefault("setup_max_age", 86400)
viper.SetDefault("reset_max_age", 3600)
viper.SetDefault("max_attempts", 10)
viper.SetDefault("bind", "")
viper.SetDefault("secret_key", "change-me")
viper.SetDefault("driver", "mysql")
viper.SetDefault("dsn", "/mokey?parseTime=true")
viper.SetDefault("rate_limit", false)
viper.SetDefault("redis", ":6379")
viper.SetDefault("max_requests", 15)
viper.SetDefault("rate_limit_expire", 3600)
gob.Register(&ipa.UserRecord{})
gob.Register(&ipa.IpaDateTime{})
if !viper.IsSet("ipahost") {
cfg, err := ini.Load("/etc/ipa/default.conf")
if err != nil {
viper.SetDefault("ipahost", "localhost")
return
}
ipaServer, err := cfg.Section("global").GetKey("server")
if err != nil {
viper.SetDefault("ipahost", "localhost")
return
}
viper.SetDefault("ipahost", ipaServer)
}
}
开发者ID:HeWhoWas,项目名称:mokey,代码行数:40,代码来源:server.go
示例20: configureTargets
func configureTargets() io.Writer {
if viper.IsSet("log.targets") {
var (
writers []io.Writer
logTargets []logTarget
)
if err := mapstructure.Decode(viper.Get("log.targets"), &logTargets); err != nil {
panic(fmt.Errorf("Failed to process log targets: %s", err))
}
for _, target := range logTargets {
switch target.Type {
case "os":
if target.Target == "stdout" {
writers = append(writers, output.Stdout())
} else if target.Target == "stderr" {
writers = append(writers, output.Stderr())
}
case "file":
file, err := os.OpenFile(target.Target, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
if err != nil {
if os.IsNotExist(err) {
file, err = os.Create(target.Target)
if err != nil {
panic(fmt.Errorf("Failed creating a file log target: %s", err))
}
} else {
panic(err)
}
}
writers = append(writers, file)
}
}
return io.MultiWriter(writers...)
}
return output.Stdout()
}
开发者ID:bbuck,项目名称:dragon-mud,代码行数:38,代码来源:logger.go
注:本文中的github.com/spf13/viper.IsSet函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论