Files
Docwell/Server/internal/config/config.go
T
tajniak81andClaude Opus 5.5 4903bb12dd Scaffold Docwell monorepo with PocketBase authentication
Phase 0 foundation for Docwell, an open-source knowledge base:

- Database: PocketBase v0.40.6 with initial schema migrations; users is
  the built-in auth collection, plus a hook for token checks and
  env-driven app URL/SMTP settings
- Server: Go API (health, version, auth endpoints forwarded to
  PocketBase, admin user list) with an embedded Vue admin panel
- Web-App: Go static server and Vue/Tailwind app with Tiptap editor,
  sign-in, sign-up, password reset and email verification (EN/PL)
- Desktop-App: Wails v3 host reusing the web app
- Phone-App: Flutter app with sign-in
- Shared packages (editor, ui, api-client), OpenAPI spec, Docker
  compose (separate services and all-in-one), GitHub Actions CI
- Docs: feature inventory and architecture/build plan

Licensed under AGPL-3.0-or-later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 22:18:25 +01:00

79 lines
2.2 KiB
Go

// Package config loads docwell-server settings from environment variables.
package config
import (
"errors"
"os"
"strings"
"time"
)
type Config struct {
// Addr is the listen address of the public API, e.g. ":8080".
Addr string
// PublicURL is the externally reachable base URL of the server.
PublicURL string
// CORSOrigins lists origins allowed to call the API from a browser.
CORSOrigins []string
// SignupEnabled allows self-service signup (the first account always can).
SignupEnabled bool
// SignupDomains limits signup to these email domains when not empty.
SignupDomains []string
PocketBaseURL string
PocketBaseEmail string
PocketBasePassword string
ShutdownTimeout time.Duration
}
// Load reads the configuration from the environment and validates it.
func Load() (Config, error) {
return fromLookup(os.LookupEnv)
}
func fromLookup(lookup func(string) (string, bool)) (Config, error) {
get := func(key, def string) string {
if v, ok := lookup(key); ok && v != "" {
return v
}
return def
}
cfg := Config{
Addr: get("DOCWELL_ADDR", ":8080"),
PublicURL: strings.TrimRight(get("DOCWELL_PUBLIC_URL", "http://localhost:8080"), "/"),
CORSOrigins: splitList(get("DOCWELL_CORS_ORIGINS", "http://localhost:5173,http://localhost:3000")),
PocketBaseURL: strings.TrimRight(get("DOCWELL_PB_URL", "http://127.0.0.1:8090"), "/"),
PocketBaseEmail: get("DOCWELL_PB_EMAIL", ""),
PocketBasePassword: get("DOCWELL_PB_PASSWORD", ""),
SignupEnabled: get("DOCWELL_SIGNUP_ENABLED", "true") == "true",
SignupDomains: splitList(get("DOCWELL_SIGNUP_DOMAINS", "")),
ShutdownTimeout: 15 * time.Second,
}
if v := get("DOCWELL_SHUTDOWN_TIMEOUT", ""); v != "" {
d, err := time.ParseDuration(v)
if err != nil {
return Config{}, errors.New("DOCWELL_SHUTDOWN_TIMEOUT: " + err.Error())
}
cfg.ShutdownTimeout = d
}
if cfg.PocketBaseEmail == "" || cfg.PocketBasePassword == "" {
return Config{}, errors.New("DOCWELL_PB_EMAIL and DOCWELL_PB_PASSWORD are required")
}
return cfg, nil
}
func splitList(s string) []string {
var out []string
for _, part := range strings.Split(s, ",") {
if part = strings.TrimSpace(part); part != "" {
out = append(out, part)
}
}
return out
}