add consts for environment and logs
This commit is contained in:
parent
3cadf06599
commit
bbbb4a28d3
33
app/app.go
33
app/app.go
@ -66,6 +66,23 @@ var (
|
|||||||
logLevel string
|
logLevel string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Environment string
|
||||||
|
|
||||||
|
const (
|
||||||
|
EnvironmentTesting Environment = "testing"
|
||||||
|
EnvironmentDevelopment Environment = "development"
|
||||||
|
EnvironmentProduction Environment = "production"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LogLevel string
|
||||||
|
|
||||||
|
const (
|
||||||
|
LogLevelDebug LogLevel = "debug"
|
||||||
|
LogLevelInfo LogLevel = "info"
|
||||||
|
LogLevelWarn LogLevel = "warn"
|
||||||
|
LogLevelError LogLevel = "error"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// default ""
|
// default ""
|
||||||
Name string
|
Name string
|
||||||
@ -77,10 +94,10 @@ type Config struct {
|
|||||||
EnvDirectory string
|
EnvDirectory string
|
||||||
|
|
||||||
// default "development"
|
// default "development"
|
||||||
EnvMode string
|
EnvMode Environment
|
||||||
|
|
||||||
// default "debug"
|
// default "debug"
|
||||||
LogLevel string
|
LogLevel LogLevel
|
||||||
|
|
||||||
// default "UTC"
|
// default "UTC"
|
||||||
Timezone string
|
Timezone string
|
||||||
@ -177,12 +194,12 @@ func New(config ...Config) *App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg.EnvMode == "" && os.Getenv("ENV_MODE") != "" {
|
if cfg.EnvMode == "" && os.Getenv("ENV_MODE") != "" {
|
||||||
cfg.EnvMode = os.Getenv("ENV_MODE")
|
cfg.EnvMode = Environment(os.Getenv("ENV_MODE"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.LogLevel == "" && os.Getenv("LOG_LEVEL") != "" {
|
if cfg.LogLevel == "" && os.Getenv("LOG_LEVEL") != "" {
|
||||||
cfg.LogLevel = os.Getenv("LOG_LEVEL")
|
cfg.LogLevel = LogLevel(os.Getenv("LOG_LEVEL"))
|
||||||
logLevel = cfg.LogLevel
|
logLevel = string(cfg.LogLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Timezone == "" && os.Getenv("TIMEZONE") != "" {
|
if cfg.Timezone == "" && os.Getenv("TIMEZONE") != "" {
|
||||||
@ -306,11 +323,11 @@ func (a *App) Version() string {
|
|||||||
return a.config.Version
|
return a.config.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) EnvMode() string {
|
func (a *App) EnvMode() Environment {
|
||||||
return a.config.EnvMode
|
return a.config.EnvMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) LogLevel() string {
|
func (a *App) LogLevel() LogLevel {
|
||||||
return a.config.LogLevel
|
return a.config.LogLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +354,7 @@ func (a *App) Timezone() string {
|
|||||||
//
|
//
|
||||||
// cmd/database/migrations/*.sql
|
// cmd/database/migrations/*.sql
|
||||||
func (a *App) Migrate(database embed.FS) {
|
func (a *App) Migrate(database embed.FS) {
|
||||||
if a.config.DatabaseMigrate == false {
|
if !a.config.DatabaseMigrate {
|
||||||
slog.Info("migration disabled")
|
slog.Info("migration disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user