|
@@ -2,6 +2,7 @@ package env
|
|
|
|
|
|
import (
|
|
|
"flag"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
)
|
|
@@ -9,30 +10,40 @@ import (
|
|
|
const defaultConfigPath = "../../.env"
|
|
|
|
|
|
type Service struct {
|
|
|
- appPort string
|
|
|
+ appPort uint64
|
|
|
+ appCORSAllowOrigins string
|
|
|
+ appCORSAllowMethods string
|
|
|
+ dbDriver string
|
|
|
dbHost string
|
|
|
- dbPort string
|
|
|
+ dbPort uint64
|
|
|
dbName string
|
|
|
dbUser string
|
|
|
dbPassword string
|
|
|
- dbMaxOpenConns int
|
|
|
- dbMaxIdleConns int
|
|
|
- dbMaxConnLifetime int
|
|
|
- dbMaxIdleConnLifetime int
|
|
|
- corsAllowOrigins string
|
|
|
- corsAllowMethods string
|
|
|
+ dbSSLMode string
|
|
|
+ dbMaxOpenConns uint16
|
|
|
+ dbMaxIdleConns uint16
|
|
|
+ dbMaxOpenConnLifetime time.Duration
|
|
|
+ dbMaxIdleConnLifetime time.Duration
|
|
|
+ cacheDefaultDuration time.Duration
|
|
|
+ cacheCleanupInterval time.Duration
|
|
|
+ smtpHost string
|
|
|
+ smtpPort uint64
|
|
|
+ smtpUser string
|
|
|
+ smtpPassword string
|
|
|
jwtSecretKey string
|
|
|
- jwtLifeTime int
|
|
|
+ jwtLifeTime time.Duration
|
|
|
jwtCookie string
|
|
|
basicAuthUser string
|
|
|
basicAuthPassword string
|
|
|
- smtpHost string
|
|
|
- smtpPort string
|
|
|
- smtpUser string
|
|
|
- smtpPassword string
|
|
|
- errorsEmail string
|
|
|
- gaKey string
|
|
|
- staticVersion int
|
|
|
+ staticVersion uint64
|
|
|
+ loggerStdoutEnabled bool
|
|
|
+ loggerStdoutLevel string
|
|
|
+ loggerStdoutAddSource bool
|
|
|
+ loggerEmailEnabled bool
|
|
|
+ loggerEmailLevel string
|
|
|
+ loggerEmailAddSource bool
|
|
|
+ loggerEmailSubject string
|
|
|
+ loggerEmail string
|
|
|
}
|
|
|
|
|
|
func Init() (*Service, error) {
|
|
@@ -53,30 +64,40 @@ func Init() (*Service, error) {
|
|
|
}
|
|
|
|
|
|
s := struct {
|
|
|
- AppPort string `mapstructure:"APP_PORT"`
|
|
|
- DBHost string `mapstructure:"DB_HOST"`
|
|
|
- DBPort string `mapstructure:"DB_PORT"`
|
|
|
- DBName string `mapstructure:"DB_NAME"`
|
|
|
- DBUser string `mapstructure:"DB_USER"`
|
|
|
- DBPassword string `mapstructure:"DB_PASSWORD"`
|
|
|
- DBMaxOpenConns int `mapstructure:"DB_MAX_OPEN_CONNS"`
|
|
|
- DBMaxIdleConns int `mapstructure:"DB_MAX_IDLE_CONNS"`
|
|
|
- DBMaxConnLifetime int `mapstructure:"DB_MAX_CONN_LIFETIME"`
|
|
|
- DBMaxIdleConnLifetime int `mapstructure:"DB_MAX_IDLE_CONN_LIFETIME"`
|
|
|
- CORSAllowOrigins string `mapstructure:"CORS_ALLOW_ORIGING"`
|
|
|
- CORSAllowMethods string `mapstructure:"CORS_ALLOW_METHODS"`
|
|
|
- JWTSecretKey string `mapstructure:"JWT_SECRET_KEY"`
|
|
|
- JWTLifeTime int `mapstructure:"JWT_LIFETIME"`
|
|
|
- JWTCookie string `mapstructure:"JWT_COOKIE"`
|
|
|
- BasicAuthUser string `mapstructure:"BASIC_AUTH_USER"`
|
|
|
- BasicAuthPassword string `mapstructure:"BASIC_AUTH_PASSWORD"`
|
|
|
- SMTPHost string `mapstructure:"SMTP_HOST"`
|
|
|
- SMTPPort string `mapstructure:"SMTP_PORT"`
|
|
|
- SMTPUser string `mapstructure:"SMTP_USER"`
|
|
|
- SMTPPassword string `mapstructure:"SMTP_PASSWORD"`
|
|
|
- ErrorsEmail string `mapstructure:"ERRORS_EMAIL"`
|
|
|
- GAKey string `mapstructure:"GA_KEY"`
|
|
|
- StaticVersion int `mapstructure:"STATIC_VERSION"`
|
|
|
+ AppPort uint64 `mapstructure:"APP_PORT"`
|
|
|
+ AppCORSAllowOrigins string `mapstructure:"APP_CORS_ALLOW_ORIGIN"`
|
|
|
+ AppCORSAllowMethods string `mapstructure:"APP_CORS_ALLOW_METHODS"`
|
|
|
+ DBDriver string `mapstructure:"DB_DRIVER"`
|
|
|
+ DBHost string `mapstructure:"DB_HOST"`
|
|
|
+ DBPort uint64 `mapstructure:"DB_PORT"`
|
|
|
+ DBName string `mapstructure:"DB_NAME"`
|
|
|
+ DBUser string `mapstructure:"DB_USER"`
|
|
|
+ DBPassword string `mapstructure:"DB_PASSWORD"`
|
|
|
+ DBSSLMode string `mapstructure:"DB_SSL_MODE"`
|
|
|
+ DBMaxOpenConns uint16 `mapstructure:"DB_MAX_OPEN_CONNS"`
|
|
|
+ DBMaxIdleConns uint16 `mapstructure:"DB_MAX_IDLE_CONNS"`
|
|
|
+ DBMaxOpenConnLifetime time.Duration `mapstructure:"DB_MAX_OPEN_CONN_LIFETIME"`
|
|
|
+ DBMaxIdleConnLifetime time.Duration `mapstructure:"DB_MAX_IDLE_CONN_LIFETIME"`
|
|
|
+ CacheDefaultDuration time.Duration `mapstructure:"CACHE_DEFAULT_EXPIRATION"`
|
|
|
+ CacheCleanupInterval time.Duration `mapstructure:"CACHE_CLEANUP_INTERVAL"`
|
|
|
+ SMTPHost string `mapstructure:"SMTP_HOST"`
|
|
|
+ SMTPPort uint64 `mapstructure:"SMTP_PORT"`
|
|
|
+ SMTPUser string `mapstructure:"SMTP_USER"`
|
|
|
+ SMTPPassword string `mapstructure:"SMTP_PASSWORD"`
|
|
|
+ JWTSecretKey string `mapstructure:"JWT_SECRET_KEY"`
|
|
|
+ JWTLifeTime time.Duration `mapstructure:"JWT_LIFETIME"`
|
|
|
+ JWTCookie string `mapstructure:"JWT_COOKIE"`
|
|
|
+ BasicAuthUser string `mapstructure:"BASIC_AUTH_USER"`
|
|
|
+ BasicAuthPassword string `mapstructure:"BASIC_AUTH_PASSWORD"`
|
|
|
+ StaticVersion uint64 `mapstructure:"STATIC_VERSION"`
|
|
|
+ LoggerStdoutEnabled bool `mapstructure:"LOGGER_STDOUT_ENABLED"`
|
|
|
+ LoggerStdoutLevel string `mapstructure:"LOGGER_STDOUT_LEVEL"`
|
|
|
+ LoggerStdoutAddSource bool `mapstructure:"LOGGER_STDOUT_ADD_SOURCE"`
|
|
|
+ LoggerEmailEnabled bool `mapstructure:"LOGGER_EMAIL_ENABLED"`
|
|
|
+ LoggerEmailLevel string `mapstructure:"LOGGER_EMAIL_LEVEL"`
|
|
|
+ LoggerEmailAddSource bool `mapstructure:"LOGGER_EMAIL_ADD_SOURCE"`
|
|
|
+ LoggerEmailSubject string `mapstructure:"LOGGER_EMAIL_SUBJECT"`
|
|
|
+ LoggerEmail string `mapstructure:"LOGGER_EMAIL"`
|
|
|
}{}
|
|
|
|
|
|
if err := viper.Unmarshal(&s); err != nil {
|
|
@@ -85,124 +106,174 @@ func Init() (*Service, error) {
|
|
|
|
|
|
return &Service{
|
|
|
appPort: s.AppPort,
|
|
|
+ appCORSAllowOrigins: s.AppCORSAllowOrigins,
|
|
|
+ appCORSAllowMethods: s.AppCORSAllowMethods,
|
|
|
+ dbDriver: s.DBDriver,
|
|
|
dbHost: s.DBHost,
|
|
|
dbPort: s.DBPort,
|
|
|
dbName: s.DBName,
|
|
|
dbUser: s.DBUser,
|
|
|
dbPassword: s.DBPassword,
|
|
|
+ dbSSLMode: s.LoggerEmail,
|
|
|
dbMaxOpenConns: s.DBMaxOpenConns,
|
|
|
dbMaxIdleConns: s.DBMaxIdleConns,
|
|
|
- dbMaxConnLifetime: s.DBMaxConnLifetime,
|
|
|
+ dbMaxOpenConnLifetime: s.DBMaxOpenConnLifetime,
|
|
|
dbMaxIdleConnLifetime: s.DBMaxIdleConnLifetime,
|
|
|
- corsAllowOrigins: s.CORSAllowOrigins,
|
|
|
- corsAllowMethods: s.CORSAllowMethods,
|
|
|
+ cacheDefaultDuration: s.CacheDefaultDuration,
|
|
|
+ cacheCleanupInterval: s.CacheCleanupInterval,
|
|
|
+ smtpHost: s.SMTPHost,
|
|
|
+ smtpPort: s.SMTPPort,
|
|
|
+ smtpUser: s.SMTPUser,
|
|
|
+ smtpPassword: s.SMTPPassword,
|
|
|
jwtSecretKey: s.JWTSecretKey,
|
|
|
jwtLifeTime: s.JWTLifeTime,
|
|
|
jwtCookie: s.JWTCookie,
|
|
|
basicAuthUser: s.BasicAuthUser,
|
|
|
basicAuthPassword: s.BasicAuthPassword,
|
|
|
- smtpHost: s.SMTPHost,
|
|
|
- smtpPort: s.SMTPPort,
|
|
|
- smtpUser: s.SMTPUser,
|
|
|
- smtpPassword: s.SMTPPassword,
|
|
|
- errorsEmail: s.ErrorsEmail,
|
|
|
- gaKey: s.GAKey,
|
|
|
staticVersion: s.StaticVersion,
|
|
|
+ loggerStdoutEnabled: s.LoggerStdoutEnabled,
|
|
|
+ loggerStdoutLevel: s.LoggerStdoutLevel,
|
|
|
+ loggerStdoutAddSource: s.LoggerStdoutAddSource,
|
|
|
+ loggerEmailEnabled: s.LoggerEmailEnabled,
|
|
|
+ loggerEmailLevel: s.LoggerEmailLevel,
|
|
|
+ loggerEmailAddSource: s.LoggerEmailAddSource,
|
|
|
+ loggerEmailSubject: s.LoggerEmailSubject,
|
|
|
+ loggerEmail: s.LoggerEmail,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
-func (e *Service) AppPort() string {
|
|
|
- return e.appPort
|
|
|
+func (s Service) AppPort() uint64 {
|
|
|
+ return s.appPort
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) AppCORSAllowOrigins() string {
|
|
|
+ return s.appCORSAllowOrigins
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) AppCORSAllowMethods() string {
|
|
|
+ return s.appCORSAllowMethods
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) DbDriver() string {
|
|
|
+ return s.dbDriver
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) DbHost() string {
|
|
|
+ return s.dbHost
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) DbPort() uint64 {
|
|
|
+ return s.dbPort
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) DbName() string {
|
|
|
+ return s.dbName
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) DbUser() string {
|
|
|
+ return s.dbUser
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) DbPassword() string {
|
|
|
+ return s.dbPassword
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) DbSSLMode() string {
|
|
|
+ return s.dbSSLMode
|
|
|
+}
|
|
|
+
|
|
|
+func (s Service) DbMaxOpenConns() uint16 {
|
|
|
+ return s.dbMaxOpenConns
|
|
|
}
|
|
|
|
|
|
-func (e *Service) DBHost() string {
|
|
|
- return e.dbHost
|
|
|
+func (s Service) DbMaxIdleConns() uint16 {
|
|
|
+ return s.dbMaxIdleConns
|
|
|
}
|
|
|
|
|
|
-func (e *Service) DBPort() string {
|
|
|
- return e.dbPort
|
|
|
+func (s Service) DbMaxOpenConnLifetime() time.Duration {
|
|
|
+ return s.dbMaxOpenConnLifetime
|
|
|
}
|
|
|
|
|
|
-func (e *Service) DBName() string {
|
|
|
- return e.dbName
|
|
|
+func (s Service) DbMaxIdleConnLifetime() time.Duration {
|
|
|
+ return s.dbMaxIdleConnLifetime
|
|
|
}
|
|
|
|
|
|
-func (e *Service) DBUser() string {
|
|
|
- return e.dbUser
|
|
|
+func (s Service) CacheDefaultDuration() time.Duration {
|
|
|
+ return s.cacheDefaultDuration
|
|
|
}
|
|
|
|
|
|
-func (e *Service) DBPassword() string {
|
|
|
- return e.dbPassword
|
|
|
+func (s Service) CacheCleanupInterval() time.Duration {
|
|
|
+ return s.cacheCleanupInterval
|
|
|
}
|
|
|
|
|
|
-func (e *Service) CORSAllowOrigins() string {
|
|
|
- return e.corsAllowOrigins
|
|
|
+func (s Service) SmtpHost() string {
|
|
|
+ return s.smtpHost
|
|
|
}
|
|
|
|
|
|
-func (e *Service) CORSAllowMethods() string {
|
|
|
- return e.corsAllowMethods
|
|
|
+func (s Service) SmtpPort() uint64 {
|
|
|
+ return s.smtpPort
|
|
|
}
|
|
|
|
|
|
-func (e *Service) DBMaxOpenConns() int {
|
|
|
- return e.dbMaxOpenConns
|
|
|
+func (s Service) SmtpUser() string {
|
|
|
+ return s.smtpUser
|
|
|
}
|
|
|
|
|
|
-func (e *Service) DBMaxIdleConns() int {
|
|
|
- return e.dbMaxIdleConns
|
|
|
+func (s Service) SmtpPassword() string {
|
|
|
+ return s.smtpPassword
|
|
|
}
|
|
|
|
|
|
-func (e *Service) DBMaxConnLifetime() int {
|
|
|
- return e.dbMaxConnLifetime
|
|
|
+func (s Service) JwtSecretKey() string {
|
|
|
+ return s.jwtSecretKey
|
|
|
}
|
|
|
|
|
|
-func (e *Service) DBMaxIdleConnLifetime() int {
|
|
|
- return e.dbMaxIdleConnLifetime
|
|
|
+func (s Service) JwtLifeTime() time.Duration {
|
|
|
+ return s.jwtLifeTime
|
|
|
}
|
|
|
|
|
|
-func (e *Service) SMTPHost() string {
|
|
|
- return e.smtpHost
|
|
|
+func (s Service) JwtCookie() string {
|
|
|
+ return s.jwtCookie
|
|
|
}
|
|
|
|
|
|
-func (e *Service) SMTPPort() string {
|
|
|
- return e.smtpPort
|
|
|
+func (s Service) BasicAuthUser() string {
|
|
|
+ return s.basicAuthUser
|
|
|
}
|
|
|
|
|
|
-func (e *Service) SMTPUser() string {
|
|
|
- return e.smtpUser
|
|
|
+func (s Service) BasicAuthPassword() string {
|
|
|
+ return s.basicAuthPassword
|
|
|
}
|
|
|
|
|
|
-func (e *Service) SMTPPassword() string {
|
|
|
- return e.smtpPassword
|
|
|
+func (s Service) StaticVersion() uint64 {
|
|
|
+ return s.staticVersion
|
|
|
}
|
|
|
|
|
|
-func (e *Service) JWTSecretKey() string {
|
|
|
- return e.jwtSecretKey
|
|
|
+func (s Service) LoggerStdoutEnabled() bool {
|
|
|
+ return s.loggerStdoutEnabled
|
|
|
}
|
|
|
|
|
|
-func (e *Service) JWTCookie() string {
|
|
|
- return e.jwtCookie
|
|
|
+func (s Service) LoggerStdoutLevel() string {
|
|
|
+ return s.loggerStdoutLevel
|
|
|
}
|
|
|
|
|
|
-func (e *Service) JWTLifetime() int {
|
|
|
- return e.jwtLifeTime
|
|
|
+func (s Service) LoggerStdoutAddSource() bool {
|
|
|
+ return s.loggerStdoutAddSource
|
|
|
}
|
|
|
|
|
|
-func (e *Service) ErrorsEmail() string {
|
|
|
- return e.errorsEmail
|
|
|
+func (s Service) LoggerEmailEnabled() bool {
|
|
|
+ return s.loggerEmailEnabled
|
|
|
}
|
|
|
|
|
|
-func (e *Service) BasicAuthUser() string {
|
|
|
- return e.basicAuthUser
|
|
|
+func (s Service) LoggerEmailLevel() string {
|
|
|
+ return s.loggerEmailLevel
|
|
|
}
|
|
|
|
|
|
-func (e *Service) BasicAuthPassword() string {
|
|
|
- return e.basicAuthPassword
|
|
|
+func (s Service) LoggerEmailAddSource() bool {
|
|
|
+ return s.loggerEmailAddSource
|
|
|
}
|
|
|
|
|
|
-func (e *Service) StaticVersion() int {
|
|
|
- return e.staticVersion
|
|
|
+func (s Service) LoggerEmailSubject() string {
|
|
|
+ return s.loggerEmailSubject
|
|
|
}
|
|
|
|
|
|
-func (e *Service) GAKey() string {
|
|
|
- return e.gaKey
|
|
|
+func (s Service) LoggerEmail() string {
|
|
|
+ return s.loggerEmail
|
|
|
}
|