main pico / pkg / apps / pico / config.go
Antonio Mika  ·  2026-10-11
 1package pico
 2
 3import (
 4	"log/slog"
 5	"strings"
 6
 7	"github.com/picosh/pico/pkg/shared"
 8)
 9
10type Config struct {
11	DbURL      string
12	Space      string
13	TunsSecret string
14	Logger     *slog.Logger
15	// CustomDomainTargets are the hosts a custom domain can point at.
16	CustomDomainTargets []string
17}
18
19func NewConfig(service string) *Config {
20	dbURL := shared.GetEnv("DATABASE_URL", "")
21	tuns := shared.GetEnv("TUNS_CONSOLE_SECRET", "")
22	withPipe := strings.ToLower(shared.GetEnv("PICO_PIPE_ENABLED", "true")) == "true"
23
24	return &Config{
25		DbURL:      dbURL,
26		Space:      "pico",
27		Logger:     shared.CreateLogger(service, withPipe),
28		TunsSecret: tuns,
29		CustomDomainTargets: []string{
30			hostOnly(shared.GetEnv("PGS_DOMAIN", "pgs.sh")),
31			hostOnly(shared.GetEnv("PROSE_DOMAIN", "prose.sh")),
32			"tuns.sh",
33			"nue.tuns.sh",
34		},
35	}
36}
37
38func hostOnly(domain string) string {
39	host, _, _ := strings.Cut(domain, ":")
40	return host
41}