43 lines
1.4 KiB
Go
Executable File
43 lines
1.4 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"`
|
|
R2AccountID string `mapstructure:"R2_ACCOUNT_ID"`
|
|
R2AccessKeyID string `mapstructure:"R2_ACCESS_KEY_ID"`
|
|
R2SecretAccessKey string `mapstructure:"R2_SECRET_ACCESS_KEY"`
|
|
R2BucketName string `mapstructure:"R2_BUCKET_NAME"`
|
|
R2PublicApiID string `mapstructure:"R2_PUBLIC_API_ID"`
|
|
RedisAddress string `mapstructure:"REDIS_ADDRESS"`
|
|
}
|
|
|
|
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
|
|
}
|