Change JWT TTL config from duration to string for flexibility
- The mapstructure library is no longer needed for direct duration parsing since we now store TTLs as string durations (e.g., "15m", "168h") and parse them on demand via helper methods. - This allows more flexible duration formats in configuration and moves the parsing responsibility to the JWT config struct itself.
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/go-viper/mapstructure/v2"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@@ -24,10 +23,6 @@ func defaults(v *viper.Viper) {
|
||||
v.SetDefault("jwt.refresh_ttl", "168h")
|
||||
}
|
||||
|
||||
func decodeHook() viper.DecoderConfigOption {
|
||||
return viper.DecodeHook(mapstructure.StringToTimeDurationHookFunc())
|
||||
}
|
||||
|
||||
func New() *viper.Viper {
|
||||
v := viper.New()
|
||||
v.SetEnvPrefix("MYGO")
|
||||
@@ -54,7 +49,7 @@ func Load(v *viper.Viper, cfgFile string) (*Config, error) {
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err := v.Unmarshal(&cfg, decodeHook()); err != nil {
|
||||
if err := v.Unmarshal(&cfg); err != nil {
|
||||
return nil, fmt.Errorf("unmarshal config: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user