Skip to content

Commit 1b74504

Browse files
authored
refactor: using reflect.TypeFor (#2731)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> Try to use better api reflect.TypeFor instead of reflect.TypeOf when we have known the type. More info golang/go#60088 Signed-off-by: russcoss <[email protected]>
1 parent 79cc094 commit 1b74504

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ func loadFromViper(v *viper.Viper, home string) (Config, error) {
472472
mapstructure.StringToTimeDurationHookFunc(),
473473
mapstructure.StringToSliceHookFunc(","),
474474
func(f reflect.Type, t reflect.Type, data any) (any, error) {
475-
if t == reflect.TypeOf(DurationWrapper{}) && f.Kind() == reflect.String {
475+
if t == reflect.TypeFor[DurationWrapper]() && f.Kind() == reflect.String {
476476
if str, ok := data.(string); ok {
477477
duration, err := time.ParseDuration(str)
478478
if err != nil {

pkg/config/yaml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (c *Config) SaveAsYaml() error {
9191
}
9292

9393
// process structs fields and comments
94-
processFields(reflect.TypeOf(Config{}), "")
94+
processFields(reflect.TypeFor[Config](), "")
9595

9696
data, err := yaml.MarshalWithOptions(c, yaml.WithComment(yamlCommentMap))
9797
if err != nil {

0 commit comments

Comments
 (0)