From 2501b673b74cf5ec87f888abb2026c73fee5af7f Mon Sep 17 00:00:00 2001 From: Haelnorr Date: Wed, 25 Feb 2026 22:47:33 +1100 Subject: [PATCH] updated ezconf --- go.mod | 8 +++--- go.sum | 16 ++++++------ internal/config/config.go | 2 +- internal/db/config.go | 18 ++++++------- internal/db/ezconf.go | 38 +++------------------------ internal/discord/config.go | 13 +++++----- internal/discord/ezconf.go | 38 +++------------------------ internal/embedfs/web/css/output.css | 12 ++++++--- internal/rbac/config.go | 2 +- internal/rbac/ezconf.go | 40 ++++------------------------- pkg/oauth/config.go | 2 +- pkg/oauth/ezconf.go | 40 ++++------------------------- pkg/slapshotapi/config.go | 4 +-- pkg/slapshotapi/ezconf.go | 40 +++-------------------------- 14 files changed, 63 insertions(+), 210 deletions(-) diff --git a/go.mod b/go.mod index b4d5e0a..d62c402 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.25.6 require ( git.haelnorr.com/h/golib/env v0.9.1 - git.haelnorr.com/h/golib/ezconf v0.1.1 - git.haelnorr.com/h/golib/hlog v0.10.4 - git.haelnorr.com/h/golib/hws v0.5.0 - git.haelnorr.com/h/golib/hwsauth v0.6.1 + git.haelnorr.com/h/golib/ezconf v0.2.1 + git.haelnorr.com/h/golib/hlog v0.11.0 + git.haelnorr.com/h/golib/hws v0.6.0 + git.haelnorr.com/h/golib/hwsauth v0.7.0 git.haelnorr.com/h/golib/notify v0.1.0 github.com/a-h/templ v0.3.977 github.com/coder/websocket v1.8.14 diff --git a/go.sum b/go.sum index dcf3129..d7bb0e2 100644 --- a/go.sum +++ b/go.sum @@ -2,14 +2,14 @@ git.haelnorr.com/h/golib/cookies v0.9.0 h1:Vf+eX1prHkKuGrQon1BHY87yaPc1H+HJFRXDO git.haelnorr.com/h/golib/cookies v0.9.0/go.mod h1:y1385YExI9gLwckCVDCYVcsFXr6N7T3brJjnJD2QIuo= git.haelnorr.com/h/golib/env v0.9.1 h1:2Vsj+mJKnO5f1Md1GO5v9ggLN5zWa0baCewcSHTjoNY= git.haelnorr.com/h/golib/env v0.9.1/go.mod h1:glUQVdA1HMKX1avTDyTyuhcr36SSxZtlJxKDT5KTztg= -git.haelnorr.com/h/golib/ezconf v0.1.1 h1:4euTSDb9jvuQQkVq+x5gHoYPYyUZPWxoOSlWCIxTZOs= -git.haelnorr.com/h/golib/ezconf v0.1.1/go.mod h1:rETDcjpcEyyeBgCiZSU617wc0XycwZSC5+IAOtXmwP8= -git.haelnorr.com/h/golib/hlog v0.10.4 h1:vpCsV/OddjIYx8F48U66WxojjmhEbeLGQAOBG4ViSRQ= -git.haelnorr.com/h/golib/hlog v0.10.4/go.mod h1:+wJ8vecQY/JITTXKmI3JfkHiUGyMs7N6wooj2wuWZbc= -git.haelnorr.com/h/golib/hws v0.5.0 h1:0CSv2f+dm/KzB/o5o6uXCyvN74iBdMTImhkyAZzU52c= -git.haelnorr.com/h/golib/hws v0.5.0/go.mod h1:dxAbbGGNzqLXhZXwgt091QsvsPBdrS+1YsNQNldNVoM= -git.haelnorr.com/h/golib/hwsauth v0.6.1 h1:3BiM6hwuYDjgfu02hshvUtr592DnWi9Epj//3N13ti0= -git.haelnorr.com/h/golib/hwsauth v0.6.1/go.mod h1:xPdxqHzr1ZU0MHlG4o8r1zEstBu4FJCdaA0ZHSFxmKA= +git.haelnorr.com/h/golib/ezconf v0.2.1 h1:axMyKtgO9Zk6E8CrYrLpMzifvpjz73yxCQq0lOtuhck= +git.haelnorr.com/h/golib/ezconf v0.2.1/go.mod h1:rETDcjpcEyyeBgCiZSU617wc0XycwZSC5+IAOtXmwP8= +git.haelnorr.com/h/golib/hlog v0.11.0 h1:tCT8HWs51Nbin58sCTLcq5re6CZqo5/IHCzk3G+S3vQ= +git.haelnorr.com/h/golib/hlog v0.11.0/go.mod h1:HjhXS5G3A0BwOZq7nu2qpNBtvOFiCa1GbAuBRxAkYqs= +git.haelnorr.com/h/golib/hws v0.6.0 h1:jwXUqT03PfrexVAC0xKVQWT2CLwN8+TDBsCK3+JWmEE= +git.haelnorr.com/h/golib/hws v0.6.0/go.mod h1:iAjdrwYZye2nsvbBGIMzVcfydV4F47qUp10MvimVCOY= +git.haelnorr.com/h/golib/hwsauth v0.7.0 h1:2uR7douZfkJ1vORUpvtS50FgGNm0GextDyMlCtrStbo= +git.haelnorr.com/h/golib/hwsauth v0.7.0/go.mod h1:VUHQwQiBy6BtY9Iyb+G3j/c/He9PmGNVDlDrWa7Id0U= git.haelnorr.com/h/golib/jwt v0.10.1 h1:1Adxt9H3Y4fWFvFjWpvg/vSFhbgCMDMxgiE3m7KvDMI= git.haelnorr.com/h/golib/jwt v0.10.1/go.mod h1:fbuPrfucT9lL0faV5+Q5Gk9WFJxPlwzRPpbMQKYZok4= git.haelnorr.com/h/golib/notify v0.1.0 h1:xdf6zd21F6n+SuGTeJiuLNMf6zFXMvwpKD0gmNq8N10= diff --git a/internal/config/config.go b/internal/config/config.go index 9643062..31fb572 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -36,7 +36,7 @@ func GetConfig(flags *Flags) (*Config, *ezconf.ConfigLoader, error) { } loader := ezconf.New() - err = loader.RegisterIntegrations( + err = loader.AddIntegrations( hlog.NewEZConfIntegration(), hws.NewEZConfIntegration(), hwsauth.NewEZConfIntegration(), diff --git a/internal/db/config.go b/internal/db/config.go index 1549437..7d5364d 100644 --- a/internal/db/config.go +++ b/internal/db/config.go @@ -6,16 +6,14 @@ import ( ) type Config struct { - User string // ENV DB_USER: Database user for authentication (required) - Password string // ENV DB_PASSWORD: Database password for authentication (required) - Host string // ENV DB_HOST: Database host address (required) - Port uint16 // ENV DB_PORT: Database port (default: 5432) - DB string // ENV DB_NAME: Database name to connect to (required) - SSL string // ENV DB_SSL: SSL mode for connection (default: disable) - - // Backup configuration - BackupDir string // ENV DB_BACKUP_DIR: Directory for database backups (default: backups) - BackupRetention int // ENV DB_BACKUP_RETENTION: Number of backups to keep (default: 10) + User string `ezconf:"DB_USER,required,description:Database user for authentication"` + Password string `ezconf:"DB_PASSWORD,required,description:Database password for authentication"` + Host string `ezconf:"DB_HOST,required,description:Database host address"` + Port uint16 `ezconf:"DB_PORT,default:5432,description:Database port"` + DB string `ezconf:"DB_NAME,required,description:Database to connect to"` + SSL string `ezconf:"DB_SSL,default:disable,description:SSL Mode"` + BackupDir string `ezconf:"DB_BACKUP_DIR,default:backups,description:Directory for database backups"` + BackupRetention int `ezconf:"DB_BACKUP_RETENTION,default:10,description:Number of backups to keep"` } func ConfigFromEnv() (any, error) { diff --git a/internal/db/ezconf.go b/internal/db/ezconf.go index 1cb08c5..b3851be 100644 --- a/internal/db/ezconf.go +++ b/internal/db/ezconf.go @@ -1,41 +1,11 @@ package db import ( - "runtime" - "strings" + "git.haelnorr.com/h/golib/ezconf" ) -// EZConfIntegration provides integration with ezconf for automatic configuration -type EZConfIntegration struct { - configFunc func() (any, error) - name string -} - -// PackagePath returns the path to the config package for source parsing -func (e EZConfIntegration) PackagePath() string { - _, filename, _, _ := runtime.Caller(0) - // Return directory of this file - return filename[:len(filename)-len("/ezconf.go")] -} - -// ConfigFunc returns the ConfigFromEnv function for ezconf -func (e EZConfIntegration) ConfigFunc() func() (any, error) { - return func() (any, error) { - return e.configFunc() - } -} - -// Name returns the name to use when registering with ezconf -func (e EZConfIntegration) Name() string { - return strings.ToLower(e.name) -} - -// GroupName returns the display name for grouping environment variables -func (e EZConfIntegration) GroupName() string { - return e.name -} - // NewEZConfIntegration creates a new EZConf integration helper -func NewEZConfIntegration() EZConfIntegration { - return EZConfIntegration{name: "DB", configFunc: ConfigFromEnv} +func NewEZConfIntegration() *ezconf.Integration { + return ezconf.NewIntegration("db", "DB", &Config{}, + func() (any, error) { return ConfigFromEnv() }) } diff --git a/internal/discord/config.go b/internal/discord/config.go index e263445..f3b92ee 100644 --- a/internal/discord/config.go +++ b/internal/discord/config.go @@ -9,12 +9,13 @@ import ( ) type Config struct { - ClientID string // ENV DISCORD_CLIENT_ID: Discord application client ID (required) - ClientSecret string // ENV DISCORD_CLIENT_SECRET: Discord application client secret (required) - OAuthScopes string // Authorisation scopes for OAuth - RedirectPath string // ENV DISCORD_REDIRECT_PATH: Path for the OAuth redirect handler (required) - BotToken string // ENV DISCORD_BOT_TOKEN: Token for the discord bot (required) - GuildID string // ENV DISCORD_GUILD_ID: ID for the discord server the bot should connect to (required) + ClientID string `ezconf:"DISCORD_CLIENT_ID,required,description:Discord application client ID"` + ClientSecret string `ezconf:"DISCORD_CLIENT_SECRET,required,description:Discord application client secret"` + RedirectPath string `ezconf:"DISCORD_REDIRECT_PATH,required,description:Path for the OAuth redirect handler"` + BotToken string `ezconf:"DISCORD_BOT_TOKEN,required,description:Token for the discord bot"` + GuildID string `ezconf:"DISCORD_GUILD_ID,required,description:ID for the discord server the bot should connect to"` + + OAuthScopes string // Authorisation scopes for OAuth } func ConfigFromEnv() (any, error) { diff --git a/internal/discord/ezconf.go b/internal/discord/ezconf.go index 8442714..5fd3f8f 100644 --- a/internal/discord/ezconf.go +++ b/internal/discord/ezconf.go @@ -1,41 +1,11 @@ package discord import ( - "runtime" - "strings" + "git.haelnorr.com/h/golib/ezconf" ) -// EZConfIntegration provides integration with ezconf for automatic configuration -type EZConfIntegration struct { - configFunc func() (any, error) - name string -} - -// PackagePath returns the path to the config package for source parsing -func (e EZConfIntegration) PackagePath() string { - _, filename, _, _ := runtime.Caller(0) - // Return directory of this file - return filename[:len(filename)-len("/ezconf.go")] -} - -// ConfigFunc returns the ConfigFromEnv function for ezconf -func (e EZConfIntegration) ConfigFunc() func() (any, error) { - return func() (any, error) { - return e.configFunc() - } -} - -// Name returns the name to use when registering with ezconf -func (e EZConfIntegration) Name() string { - return strings.ToLower(e.name) -} - -// GroupName returns the display name for grouping environment variables -func (e EZConfIntegration) GroupName() string { - return e.name -} - // NewEZConfIntegration creates a new EZConf integration helper -func NewEZConfIntegration() EZConfIntegration { - return EZConfIntegration{name: "Discord", configFunc: ConfigFromEnv} +func NewEZConfIntegration() *ezconf.Integration { + return ezconf.NewIntegration("discord", "Discord", &Config{}, + func() (any, error) { return ConfigFromEnv() }) } diff --git a/internal/embedfs/web/css/output.css b/internal/embedfs/web/css/output.css index f22972c..bf6a9fc 100644 --- a/internal/embedfs/web/css/output.css +++ b/internal/embedfs/web/css/output.css @@ -1,4 +1,4 @@ -/*! tailwindcss v4.1.18 | MIT License | https://tailwindcss.com */ +/*! tailwindcss v4.2.1 | MIT License | https://tailwindcss.com */ @import url("https://fonts.googleapis.com/css2?family=Ubuntu+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap"); @layer properties; @layer theme, base, components, utilities; @@ -248,6 +248,12 @@ .inset-0 { inset: calc(var(--spacing) * 0); } + .start { + inset-inline-start: var(--spacing); + } + .end { + inset-inline-end: var(--spacing); + } .end-0 { inset-inline-end: calc(var(--spacing) * 0); } @@ -258,7 +264,7 @@ top: calc(var(--spacing) * 0); } .top-1\/2 { - top: calc(1/2 * 100%); + top: calc(1 / 2 * 100%); } .top-4 { top: calc(var(--spacing) * 4); @@ -601,7 +607,7 @@ flex-shrink: 0; } .-translate-y-1\/2 { - --tw-translate-y: calc(calc(1/2 * 100%) * -1); + --tw-translate-y: calc(calc(1 / 2 * 100%) * -1); translate: var(--tw-translate-x) var(--tw-translate-y); } .translate-y-0 { diff --git a/internal/rbac/config.go b/internal/rbac/config.go index b30843a..8559c00 100644 --- a/internal/rbac/config.go +++ b/internal/rbac/config.go @@ -8,7 +8,7 @@ import ( ) type Config struct { - AdminDiscordID string // ENV ADMIN_DISCORD_ID: Discord ID to grant admin role on first login (required) + AdminDiscordID string `ezconf:"ADMIN_DISCORD_ID,required,description:Discord ID to grant admin role on first login"` } func ConfigFromEnv() (any, error) { diff --git a/internal/rbac/ezconf.go b/internal/rbac/ezconf.go index d477a1b..e71b286 100644 --- a/internal/rbac/ezconf.go +++ b/internal/rbac/ezconf.go @@ -1,41 +1,11 @@ package rbac import ( - "runtime" - "strings" + "git.haelnorr.com/h/golib/ezconf" ) -// EZConfIntegration provides integration with ezconf for automatic configuration -type EZConfIntegration struct { - configFunc func() (any, error) - name string -} - -// PackagePath returns the path to the config package for source parsing -func (e EZConfIntegration) PackagePath() string { - _, filename, _, _ := runtime.Caller(0) - // Return directory of this file - return filename[:len(filename)-len("/ezconf.go")] -} - -// ConfigFunc returns the ConfigFromEnv function for ezconf -func (e EZConfIntegration) ConfigFunc() func() (any, error) { - return func() (any, error) { - return e.configFunc() - } -} - -// Name returns the name to use when registering with ezconf -func (e EZConfIntegration) Name() string { - return strings.ToLower(e.name) -} - -// GroupName returns the display name for grouping environment variables -func (e EZConfIntegration) GroupName() string { - return e.name -} - -// NewEZConfIntegration creates a new EZConf integration helper -func NewEZConfIntegration() EZConfIntegration { - return EZConfIntegration{name: "RBAC", configFunc: ConfigFromEnv} +// NewEZConfIntegration creates a new EZConf integration +func NewEZConfIntegration() *ezconf.Integration { + return ezconf.NewIntegration("rbac", "RBAC", &Config{}, + func() (any, error) { return ConfigFromEnv() }) } diff --git a/pkg/oauth/config.go b/pkg/oauth/config.go index 09a21e5..abb0671 100644 --- a/pkg/oauth/config.go +++ b/pkg/oauth/config.go @@ -7,7 +7,7 @@ import ( ) type Config struct { - PrivateKey string // ENV OAUTH_PRIVATE_KEY: Private key for signing OAuth state tokens (required) + PrivateKey string `ezconf:"OAUTH_PRIVATE_KEY,required,description:Private key for signing OAuth state tokens"` } func ConfigFromEnv() (any, error) { diff --git a/pkg/oauth/ezconf.go b/pkg/oauth/ezconf.go index e8a87ca..21406cb 100644 --- a/pkg/oauth/ezconf.go +++ b/pkg/oauth/ezconf.go @@ -1,41 +1,11 @@ package oauth import ( - "runtime" - "strings" + "git.haelnorr.com/h/golib/ezconf" ) -// EZConfIntegration provides integration with ezconf for automatic configuration -type EZConfIntegration struct { - configFunc func() (any, error) - name string -} - -// PackagePath returns the path to the config package for source parsing -func (e EZConfIntegration) PackagePath() string { - _, filename, _, _ := runtime.Caller(0) - // Return directory of this file - return filename[:len(filename)-len("/ezconf.go")] -} - -// ConfigFunc returns the ConfigFromEnv function for ezconf -func (e EZConfIntegration) ConfigFunc() func() (any, error) { - return func() (any, error) { - return e.configFunc() - } -} - -// Name returns the name to use when registering with ezconf -func (e EZConfIntegration) Name() string { - return strings.ToLower(e.name) -} - -// GroupName returns the display name for grouping environment variables -func (e EZConfIntegration) GroupName() string { - return e.name -} - -// NewEZConfIntegration creates a new EZConf integration helper -func NewEZConfIntegration() EZConfIntegration { - return EZConfIntegration{name: "OAuth", configFunc: ConfigFromEnv} +// NewEZConfIntegration creates a new EZConf integration +func NewEZConfIntegration() *ezconf.Integration { + return ezconf.NewIntegration("oauth", "OAuth", &Config{}, + func() (any, error) { return ConfigFromEnv() }) } diff --git a/pkg/slapshotapi/config.go b/pkg/slapshotapi/config.go index 0496f54..79d9228 100644 --- a/pkg/slapshotapi/config.go +++ b/pkg/slapshotapi/config.go @@ -7,8 +7,8 @@ import ( ) type Config struct { - Environment string // ENV SLAPSHOT_ENVIRONMENT: API environment to connect to (default: staging) - Key string // ENV SLAPSHOT_API_KEY: API Key for authorisation with the API (required) + Environment string `ezconf:"SLAPSHOT_ENVIRONMENT,default:staging,description:API environment to connect to"` + Key string `ezconf:"SLAPSHOT_API_KEY,required,description:API Key for authorisation with the API"` } func ConfigFromEnv() (any, error) { diff --git a/pkg/slapshotapi/ezconf.go b/pkg/slapshotapi/ezconf.go index b8eeb70..c51d201 100644 --- a/pkg/slapshotapi/ezconf.go +++ b/pkg/slapshotapi/ezconf.go @@ -1,41 +1,9 @@ package slapshotapi -import ( - "runtime" - "strings" -) - -// EZConfIntegration provides integration with ezconf for automatic configuration -type EZConfIntegration struct { - configFunc func() (any, error) - name string -} - -// PackagePath returns the path to the config package for source parsing -func (e EZConfIntegration) PackagePath() string { - _, filename, _, _ := runtime.Caller(0) - // Return directory of this file - return filename[:len(filename)-len("/ezconf.go")] -} - -// ConfigFunc returns the ConfigFromEnv function for ezconf -func (e EZConfIntegration) ConfigFunc() func() (any, error) { - return func() (any, error) { - return e.configFunc() - } -} - -// Name returns the name to use when registering with ezconf -func (e EZConfIntegration) Name() string { - return strings.ToLower(e.name) -} - -// GroupName returns the display name for grouping environment variables -func (e EZConfIntegration) GroupName() string { - return e.name -} +import "git.haelnorr.com/h/golib/ezconf" // NewEZConfIntegration creates a new EZConf integration helper -func NewEZConfIntegration() EZConfIntegration { - return EZConfIntegration{name: "SlapshotAPI", configFunc: ConfigFromEnv} +func NewEZConfIntegration() *ezconf.Integration { + return ezconf.NewIntegration("slapshotapi", "SlapshotAPI", &Config{}, + func() (any, error) { return ConfigFromEnv() }) }