Add full shop application: Go backend, PostgreSQL, Docker, Caddy and admin panel.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AdminEmail string
|
||||
AdminPassword string
|
||||
SessionSecret string
|
||||
}
|
||||
|
||||
func Load() Config {
|
||||
cfg := Config{
|
||||
AdminEmail: os.Getenv("ADMIN_EMAIL"),
|
||||
AdminPassword: os.Getenv("ADMIN_PASSWORD"),
|
||||
SessionSecret: os.Getenv("SESSION_SECRET"),
|
||||
}
|
||||
|
||||
if cfg.SessionSecret == "" {
|
||||
cfg.SessionSecret = randomSecret()
|
||||
log.Println("warning: SESSION_SECRET not set, using random value (sessions reset on restart)")
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func randomSecret() string {
|
||||
b := make([]byte, 32)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return hex.EncodeToString(b)
|
||||
}
|
||||
Reference in New Issue
Block a user