hiling_go/util/config.go
2024-05-22 11:26:15 +07:00

37 lines
1.0 KiB
Go
Executable File

package util
import (
"time"
"github.com/spf13/viper"
)
type Config struct {
DBDriver string `mapstructure:"DB_TYPE"`
DBSource string `mapstructure:"DB_SOURCE"`
DBSourceTest string `mapstructure:"DB_SOURCE_TEST"`
ServerAddress string `mapstructure:"SERVER_ADDRESS"`
TokenSymmetricKey string `mapstructure:"TOKEN_SYMMETRIC_KEY"`
TokenDuration time.Duration `mapstructure:"TOKEN_DURATION"`
CookieDuration int32 `mapstructure:"COOKIE_DURATION"`
RefreshTokenDuration time.Duration `mapstructure:"REFRESH_TOKEN_DURATION"`
MeilisearchHost string `mapstructure:"MEILISEARCH_HOST"`
MeilisearchKey string `mapstructure:"MEILISEARCH_KEY"`
}
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
}