Skip to content

Commit 3665354

Browse files
committed
fix a compilation issue
1 parent 3c6b770 commit 3665354

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ unit_test_race:
6767
rebuild_docs:
6868
./earthly.sh +rebuild-docs
6969

70-
ci-golang:
71-
./earthly.sh +ci-golang
70+
lint:
71+
golangci-lint run --fix

pkg/config/config.go

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strings"
66
"time"
77

8-
"github.com/mitchellh/mapstructure"
98
"github.com/pkg/errors"
109
"github.com/rs/zerolog"
1110
"github.com/rs/zerolog/log"
@@ -90,38 +89,38 @@ type ServerConfig struct {
9089
Identifier string `mapstructure:"identifier"`
9190
}
9291

92+
func viperParser(in reflect.Type, out reflect.Type, value interface{}) (interface{}, error) {
93+
if in.String() == "string" && out.String() == "zerolog.Level" {
94+
input := value.(string)
95+
return zerolog.ParseLevel(input)
96+
}
97+
98+
if in.String() == "string" && out.String() == "pkg.CommitState" {
99+
input := value.(string)
100+
return pkg.ParseCommitState(input)
101+
}
102+
103+
if in.String() == "string" && out.String() == "time.Duration" {
104+
input := value.(string)
105+
return time.ParseDuration(input)
106+
}
107+
108+
if in.String() == "string" && out.String() == "[]string" {
109+
input := value.(string)
110+
ns := strings.Split(input, ",")
111+
return ns, nil
112+
}
113+
114+
return value, nil
115+
}
116+
93117
func New() (ServerConfig, error) {
94118
return NewWithViper(viper.GetViper())
95119
}
96120

97121
func NewWithViper(v *viper.Viper) (ServerConfig, error) {
98122
var cfg ServerConfig
99-
if err := v.Unmarshal(&cfg, func(config *mapstructure.DecoderConfig) {
100-
config.DecodeHook = func(in reflect.Type, out reflect.Type, value interface{}) (interface{}, error) {
101-
if in.String() == "string" && out.String() == "zerolog.Level" {
102-
input := value.(string)
103-
return zerolog.ParseLevel(input)
104-
}
105-
106-
if in.String() == "string" && out.String() == "pkg.CommitState" {
107-
input := value.(string)
108-
return pkg.ParseCommitState(input)
109-
}
110-
111-
if in.String() == "string" && out.String() == "time.Duration" {
112-
input := value.(string)
113-
return time.ParseDuration(input)
114-
}
115-
116-
if in.String() == "string" && out.String() == "[]string" {
117-
input := value.(string)
118-
ns := strings.Split(input, ",")
119-
return ns, nil
120-
}
121-
122-
return value, nil
123-
}
124-
}); err != nil {
123+
if err := v.Unmarshal(&cfg, viper.DecodeHook(viperParser)); err != nil {
125124
return cfg, errors.Wrap(err, "failed to read configuration")
126125
}
127126

0 commit comments

Comments
 (0)