本文整理匯總了Golang中github.com/nttlabs/cli/generic.Map.Has方法的典型用法代碼示例。如果您正苦於以下問題:Golang Map.Has方法的具體用法?Golang Map.Has怎麽用?Golang Map.Has使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nttlabs/cli/generic.Map
的用法示例。
在下文中一共展示了Map.Has方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sliceOrEmptyVal
func sliceOrEmptyVal(yamlMap generic.Map, key string, errs *[]error) *[]string {
if !yamlMap.Has(key) {
return new([]string)
}
var (
stringSlice []string
err error
)
sliceErr := errors.NewWithFmt(T("Expected {{.PropertyName}} to be a list of strings.",
map[string]interface{}{"PropertyName": key}))
switch input := yamlMap.Get(key).(type) {
case []interface{}:
for _, value := range input {
stringValue, ok := value.(string)
if !ok {
err = sliceErr
break
}
stringSlice = append(stringSlice, stringValue)
}
default:
err = sliceErr
}
if err != nil {
*errs = append(*errs, err)
return nil
}
return &stringSlice
}
示例2: getAppMaps
func (m Manifest) getAppMaps(data generic.Map) (apps []generic.Map, errs []error) {
globalProperties := data.Except([]interface{}{"applications"})
if data.Has("applications") {
appMaps, ok := data.Get("applications").([]interface{})
if !ok {
errs = append(errs, errors.New(T("Expected applications to be a list")))
return
}
for _, appData := range appMaps {
if !generic.IsMappable(appData) {
errs = append(errs, errors.NewWithFmt(T("Expected application to be a list of key/value pairs\nError occurred in manifest near:\n'{{.YmlSnippet}}'",
map[string]interface{}{"YmlSnippet": appData})))
continue
}
appMap := generic.DeepMerge(globalProperties, generic.NewMap(appData))
apps = append(apps, appMap)
}
} else {
apps = append(apps, globalProperties)
}
return
}
示例3: stringValOrDefault
func stringValOrDefault(yamlMap generic.Map, key string, errs *[]error) *string {
if !yamlMap.Has(key) {
return nil
}
empty := ""
switch val := yamlMap.Get(key).(type) {
case string:
if val == "default" {
return &empty
} else {
return &val
}
case nil:
return &empty
default:
*errs = append(*errs, errors.NewWithFmt(T("{{.PropertyName}} must be a string or null value", map[string]interface{}{"PropertyName": key})))
return nil
}
}