feat(m1): backend scaffold - entries CRUD, start/stop, auth, migrations
This commit is contained in:
45
internal/config/config.go
Normal file
45
internal/config/config.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Config holds runtime configuration loaded from environment variables.
|
||||
type Config struct {
|
||||
AuthToken string
|
||||
Port string
|
||||
DBPath string
|
||||
Timezone string
|
||||
}
|
||||
|
||||
// Load reads configuration from environment variables, returning an error if
|
||||
// required variables are missing.
|
||||
func Load() (*Config, error) {
|
||||
token := os.Getenv("AUTH_TOKEN")
|
||||
if token == "" {
|
||||
return nil, fmt.Errorf("AUTH_TOKEN environment variable is required")
|
||||
}
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
dbPath := os.Getenv("DB_PATH")
|
||||
if dbPath == "" {
|
||||
dbPath = "wotra.db"
|
||||
}
|
||||
|
||||
tz := os.Getenv("TZ")
|
||||
if tz == "" {
|
||||
tz = "UTC"
|
||||
}
|
||||
|
||||
return &Config{
|
||||
AuthToken: token,
|
||||
Port: port,
|
||||
DBPath: dbPath,
|
||||
Timezone: tz,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user