first commit

This commit is contained in:
kenneth
2023-11-28 09:50:42 +00:00
parent d940668996
commit 5a01af92af
33 changed files with 1939 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package config
import (
"time"
"github.com/spf13/viper"
)
type Config struct {
DBDriver string `mapstructure:"DB_DRIVER"`
DBSource string `mapstructure:"DB_SOURCE"`
ServerAddress string `mapstructure:"SERVER_ADDRESS"`
TokenSymmetricKey string `mapstructure:"TOKEN_SYMMETRIC_KEY"`
AccessTokenDuration time.Duration `mapstructure:"ACCESS_TOKEN_DURATION"`
}
func LoadConfig(path string) (*Config, error) {
viper.AddConfigPath(path)
viper.SetConfigName("app")
viper.SetConfigType("env")
// 自动识别加载环境变量
viper.AutomaticEnv()
err := viper.ReadInConfig()
if err != nil {
return nil, err
}
var config Config
err = viper.Unmarshal(&config)
return &config, err
}