naise_pos/util/config.go

33 lines
759 B
Go
Raw Permalink Normal View History

2023-03-08 15:22:57 +07:00
package util
2023-03-14 17:39:40 +07:00
import (
"time"
"github.com/spf13/viper"
)
2023-03-08 15:22:57 +07:00
type Config struct {
2023-03-16 12:21:41 +07:00
DBDriver string `mapstructure:"DB_TYPE"`
DBSource string `mapstructure:"DB_SOURCE"`
ServerAddress string `mapstructure:"SERVER_ADDRESS"`
TokenSymmetricKey string `mapstructure:"TOKEN_SYMMETRIC_KEY"`
TokenDuration time.Duration `mapstructure:"TOKEN_DURATION"`
RefreshTokenDuration time.Duration `mapstructure:"REFRESH_TOKEN_DURATION"`
2023-03-08 15:22:57 +07:00
}
func LoadConfig(path string) (config Config, err error) {
viper.AddConfigPath(path)
viper.SetConfigName("dev")
viper.SetConfigType("env")
viper.AutomaticEnv()
err = viper.ReadInConfig()
if err != nil {
return
}
err = viper.Unmarshal(&config)
return
}