2023-09-08 22:25:22 +07:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
DBDriver string `mapstructure:"DB_TYPE"`
|
|
|
|
DBSource string `mapstructure:"DB_SOURCE"`
|
2023-09-12 17:07:57 +07:00
|
|
|
DBSourceTest string `mapstructure:"DB_SOURCE_TEST"`
|
2023-09-08 22:25:22 +07:00
|
|
|
ServerAddress string `mapstructure:"SERVER_ADDRESS"`
|
|
|
|
TokenSymmetricKey string `mapstructure:"TOKEN_SYMMETRIC_KEY"`
|
|
|
|
TokenDuration time.Duration `mapstructure:"TOKEN_DURATION"`
|
2023-09-27 21:58:14 +07:00
|
|
|
CookieDuration int32 `mapstructure:"COOKIE_DURATION"`
|
2023-09-08 22:25:22 +07:00
|
|
|
RefreshTokenDuration time.Duration `mapstructure:"REFRESH_TOKEN_DURATION"`
|
2024-03-03 19:31:14 +07:00
|
|
|
MeilisearchHost string `mapstructure:"MEILISEARCH_HOST"`
|
|
|
|
MeilisearchKey string `mapstructure:"MEILISEARCH_KEY"`
|
2023-09-08 22:25:22 +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
|
|
|
|
}
|