add store directory creation
This commit is contained in:
+33
-10
@@ -9,37 +9,45 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const defaultAPISessionExpirationDuration = 30 * time.Second
|
||||
const defaultPort = 8585
|
||||
const (
|
||||
defaultAPISessionExpirationDuration = 30 * time.Second
|
||||
defaultPort = 8585
|
||||
defaultMainDir = "./store"
|
||||
)
|
||||
|
||||
var GetEnv = sync.OnceValue[env](newEnv)
|
||||
var env = sync.OnceValue[environment](newEnv)()
|
||||
|
||||
type env struct {
|
||||
type environment struct {
|
||||
adminUsername string
|
||||
adminPassword string
|
||||
sessionExpirationDuration time.Duration
|
||||
port int
|
||||
isSecure bool
|
||||
storeDir string
|
||||
}
|
||||
|
||||
func (e env) GetCredentials() (username, password string) {
|
||||
func (e environment) GetCredentials() (username, password string) {
|
||||
return e.adminUsername, e.adminPassword
|
||||
}
|
||||
|
||||
func (e env) GetSessionExpirationDuration() time.Duration {
|
||||
func (e environment) GetSessionExpirationDuration() time.Duration {
|
||||
return e.sessionExpirationDuration
|
||||
}
|
||||
|
||||
func (e env) GetPort() int {
|
||||
func (e environment) GetPort() int {
|
||||
return e.port
|
||||
}
|
||||
|
||||
func (e env) IsSecure() bool {
|
||||
func (e environment) IsSecure() bool {
|
||||
return e.isSecure
|
||||
}
|
||||
|
||||
func newEnv() env {
|
||||
env := env{
|
||||
func (e environment) GetDir() string {
|
||||
return e.storeDir
|
||||
}
|
||||
|
||||
func newEnv() environment {
|
||||
env := environment{
|
||||
adminUsername: os.Getenv("API_ADMIN_USERNAME"),
|
||||
adminPassword: os.Getenv("API_ADMIN_PASSWORD"),
|
||||
isSecure: os.Getenv("API_SECURE") == "true",
|
||||
@@ -59,5 +67,20 @@ func newEnv() env {
|
||||
env.port = defaultPort
|
||||
}
|
||||
|
||||
storeDir := os.Getenv("API_STORE_DIR")
|
||||
if storeDir == "" {
|
||||
storeDir = defaultMainDir
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(storeDir, 0755); err != nil { //nolint
|
||||
log.Fatal().Err(err).Msg("unable to create store dir")
|
||||
}
|
||||
|
||||
env.storeDir = storeDir
|
||||
|
||||
return env
|
||||
}
|
||||
|
||||
func GetEnv() environment {
|
||||
return env
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user