docs: adjust key generators (#4825)
parent
a33b37a9cd
commit
8319778b5d
|
@ -177,7 +177,7 @@ func codeKeysRunE(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
|
||||||
data := tmplConfigurationKeysData{
|
data := tmplConfigurationKeysData{
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
Keys: readTags("", reflect.TypeOf(schema.Configuration{})),
|
Keys: readTags("", reflect.TypeOf(schema.Configuration{}), false),
|
||||||
}
|
}
|
||||||
|
|
||||||
if root, err = cmd.Flags().GetString(cmdFlagRoot); err != nil {
|
if root, err = cmd.Flags().GetString(cmdFlagRoot); err != nil {
|
||||||
|
|
|
@ -89,13 +89,9 @@ func docsKeysRunE(cmd *cobra.Command, args []string) (err error) {
|
||||||
data []ConfigurationKey
|
data []ConfigurationKey
|
||||||
)
|
)
|
||||||
|
|
||||||
keys := readTags("", reflect.TypeOf(schema.Configuration{}))
|
keys := readTags("", reflect.TypeOf(schema.Configuration{}), true)
|
||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if strings.Contains(key, "[]") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
ck := ConfigurationKey{
|
ck := ConfigurationKey{
|
||||||
Path: key,
|
Path: key,
|
||||||
Secret: configuration.IsSecretKey(key),
|
Secret: configuration.IsSecretKey(key),
|
||||||
|
|
|
@ -83,12 +83,16 @@ func containsType(needle reflect.Type, haystack []reflect.Type) (contains bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocyclo
|
//nolint:gocyclo
|
||||||
func readTags(prefix string, t reflect.Type) (tags []string) {
|
func readTags(prefix string, t reflect.Type, envSkip bool) (tags []string) {
|
||||||
tags = make([]string, 0)
|
tags = make([]string, 0)
|
||||||
|
|
||||||
|
if envSkip && (t.Kind() == reflect.Slice || t.Kind() == reflect.Map) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if t.Kind() != reflect.Struct {
|
if t.Kind() != reflect.Struct {
|
||||||
if t.Kind() == reflect.Slice {
|
if t.Kind() == reflect.Slice {
|
||||||
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, "", true, false), t.Elem())...)
|
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, "", true, false), t.Elem(), envSkip)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -108,34 +112,42 @@ func readTags(prefix string, t reflect.Type) (tags []string) {
|
||||||
switch kind := field.Type.Kind(); kind {
|
switch kind := field.Type.Kind(); kind {
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
if !containsType(field.Type, decodedTypes) {
|
if !containsType(field.Type, decodedTypes) {
|
||||||
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, false, false), field.Type)...)
|
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, false, false), field.Type, envSkip)...)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
case reflect.Slice, reflect.Map:
|
case reflect.Slice, reflect.Map:
|
||||||
|
if envSkip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
switch field.Type.Elem().Kind() {
|
switch field.Type.Elem().Kind() {
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
if !containsType(field.Type.Elem(), decodedTypes) {
|
if !containsType(field.Type.Elem(), decodedTypes) {
|
||||||
tags = append(tags, getKeyNameFromTagAndPrefix(prefix, tag, false, false))
|
tags = append(tags, getKeyNameFromTagAndPrefix(prefix, tag, false, false))
|
||||||
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, kind == reflect.Slice, kind == reflect.Map), field.Type.Elem())...)
|
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, kind == reflect.Slice, kind == reflect.Map), field.Type.Elem(), envSkip)...)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, kind == reflect.Slice, kind == reflect.Map), field.Type.Elem())...)
|
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, kind == reflect.Slice, kind == reflect.Map), field.Type.Elem(), envSkip)...)
|
||||||
}
|
}
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
switch field.Type.Elem().Kind() {
|
switch field.Type.Elem().Kind() {
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
if !containsType(field.Type.Elem(), decodedTypes) {
|
if !containsType(field.Type.Elem(), decodedTypes) {
|
||||||
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, false, false), field.Type.Elem())...)
|
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, false, false), field.Type.Elem(), envSkip)...)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
case reflect.Slice:
|
case reflect.Slice, reflect.Map:
|
||||||
|
if envSkip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if field.Type.Elem().Elem().Kind() == reflect.Struct {
|
if field.Type.Elem().Elem().Kind() == reflect.Struct {
|
||||||
if !containsType(field.Type.Elem(), decodedTypes) {
|
if !containsType(field.Type.Elem(), decodedTypes) {
|
||||||
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, true, false), field.Type.Elem())...)
|
tags = append(tags, readTags(getKeyNameFromTagAndPrefix(prefix, tag, true, false), field.Type.Elem(), envSkip)...)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue