本文整理匯總了Golang中github.com/fatih/structs.Field.Field方法的典型用法代碼示例。如果您正苦於以下問題:Golang Field.Field方法的具體用法?Golang Field.Field怎麽用?Golang Field.Field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fatih/structs.Field
的用法示例。
在下文中一共展示了Field.Field方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: processField
// processField gets leading name for the env variable and combines the current
// field's name and generates environment variable names recursively
func (e *EnvironmentLoader) processField(prefix string, field *structs.Field, name string, strctMap interface{}) error {
fieldName := e.generateFieldName(prefix, name)
switch strctMap.(type) {
case map[string]interface{}:
for key, val := range strctMap.(map[string]interface{}) {
field := field.Field(key)
if err := e.processField(fieldName, field, key, val); err != nil {
return err
}
}
default:
v := os.Getenv(fieldName)
if v == "" {
return nil
}
if err := fieldSet(field, v); err != nil {
return err
}
}
return nil
}
示例2: printField
// printField prints the field of the config struct for the flag.Usage
func (e *EnvironmentLoader) printField(prefix string, field *structs.Field, name string, strctMap interface{}) {
fieldName := e.generateFieldName(prefix, name)
switch strctMap.(type) {
case map[string]interface{}:
smap := strctMap.(map[string]interface{})
keys := make([]string, 0, len(smap))
for key := range smap {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
field := field.Field(key)
e.printField(fieldName, field, key, smap[key])
}
default:
fmt.Println(" ", fieldName)
}
}