Refactor to use reflect.TypeFor
This commit is contained in:
parent
50f95dd909
commit
86422af988
5 changed files with 6 additions and 6 deletions
|
|
@ -156,7 +156,7 @@ func extractType(element interface{}) string {
|
|||
for i := range v.NumField() {
|
||||
field := v.Field(i)
|
||||
|
||||
if field.Kind() == reflect.Map && field.Type().Elem() == reflect.TypeOf(dynamic.PluginConf{}) {
|
||||
if field.Kind() == reflect.Map && field.Type().Elem() == reflect.TypeFor[dynamic.PluginConf]() {
|
||||
if keys := field.MapKeys(); len(keys) == 1 {
|
||||
return keys[0].String()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ func getProviders(conf static.Configuration) []string {
|
|||
if !field.IsNil() {
|
||||
providers = append(providers, v.Type().Field(i).Name)
|
||||
}
|
||||
} else if field.Kind() == reflect.Map && field.Type().Elem() == reflect.TypeOf(static.PluginConf{}) {
|
||||
} else if field.Kind() == reflect.Map && field.Type().Elem() == reflect.TypeFor[static.PluginConf]() {
|
||||
for _, value := range field.MapKeys() {
|
||||
providers = append(providers, "plugin-"+value.String())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ func fill(field reflect.Value) error {
|
|||
setTyped(field, int32(defaultNumber))
|
||||
case reflect.Int64:
|
||||
switch field.Type() {
|
||||
case reflect.TypeOf(types.Duration(time.Second)):
|
||||
case reflect.TypeFor[types.Duration]():
|
||||
setTyped(field, types.Duration(defaultNumber*time.Second))
|
||||
default:
|
||||
setTyped(field, int64(defaultNumber))
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func doOnJSON(input string) string {
|
|||
}
|
||||
|
||||
func doOnStruct(field reflect.Value, tag string, redactByDefault bool) error {
|
||||
if field.Type().AssignableTo(reflect.TypeOf(dynamic.PluginConf{})) {
|
||||
if field.Type().AssignableTo(reflect.TypeFor[dynamic.PluginConf]()) {
|
||||
resetPlugin(field)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -164,7 +164,7 @@ func reset(field reflect.Value, name string) error {
|
|||
}
|
||||
case reflect.String:
|
||||
if field.String() != "" {
|
||||
if field.Type().AssignableTo(reflect.TypeOf(types.FileOrContent(""))) {
|
||||
if field.Type().AssignableTo(reflect.TypeFor[types.FileOrContent]()) {
|
||||
field.Set(reflect.ValueOf(types.FileOrContent(maskShort)))
|
||||
} else {
|
||||
field.Set(reflect.ValueOf(maskShort))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue