本文整理汇总了Golang中github.com/spf13/viper.IsSet函数的典型用法代码示例。如果您正苦于以下问题:Golang IsSet函数的具体用法?Golang IsSet怎么用?Golang IsSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsSet函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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)
}
示例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:
}
}
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
}
}
示例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"))
}
示例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)
}
}