updated ezconf

This commit is contained in:
2026-02-25 22:47:33 +11:00
parent 050c1f7350
commit 2501b673b7
14 changed files with 63 additions and 210 deletions

8
go.mod
View File

@@ -4,10 +4,10 @@ go 1.25.6
require ( require (
git.haelnorr.com/h/golib/env v0.9.1 git.haelnorr.com/h/golib/env v0.9.1
git.haelnorr.com/h/golib/ezconf v0.1.1 git.haelnorr.com/h/golib/ezconf v0.2.1
git.haelnorr.com/h/golib/hlog v0.10.4 git.haelnorr.com/h/golib/hlog v0.11.0
git.haelnorr.com/h/golib/hws v0.5.0 git.haelnorr.com/h/golib/hws v0.6.0
git.haelnorr.com/h/golib/hwsauth v0.6.1 git.haelnorr.com/h/golib/hwsauth v0.7.0
git.haelnorr.com/h/golib/notify v0.1.0 git.haelnorr.com/h/golib/notify v0.1.0
github.com/a-h/templ v0.3.977 github.com/a-h/templ v0.3.977
github.com/coder/websocket v1.8.14 github.com/coder/websocket v1.8.14

16
go.sum
View File

@@ -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/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 h1:2Vsj+mJKnO5f1Md1GO5v9ggLN5zWa0baCewcSHTjoNY=
git.haelnorr.com/h/golib/env v0.9.1/go.mod h1:glUQVdA1HMKX1avTDyTyuhcr36SSxZtlJxKDT5KTztg= 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.2.1 h1:axMyKtgO9Zk6E8CrYrLpMzifvpjz73yxCQq0lOtuhck=
git.haelnorr.com/h/golib/ezconf v0.1.1/go.mod h1:rETDcjpcEyyeBgCiZSU617wc0XycwZSC5+IAOtXmwP8= git.haelnorr.com/h/golib/ezconf v0.2.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.11.0 h1:tCT8HWs51Nbin58sCTLcq5re6CZqo5/IHCzk3G+S3vQ=
git.haelnorr.com/h/golib/hlog v0.10.4/go.mod h1:+wJ8vecQY/JITTXKmI3JfkHiUGyMs7N6wooj2wuWZbc= git.haelnorr.com/h/golib/hlog v0.11.0/go.mod h1:HjhXS5G3A0BwOZq7nu2qpNBtvOFiCa1GbAuBRxAkYqs=
git.haelnorr.com/h/golib/hws v0.5.0 h1:0CSv2f+dm/KzB/o5o6uXCyvN74iBdMTImhkyAZzU52c= git.haelnorr.com/h/golib/hws v0.6.0 h1:jwXUqT03PfrexVAC0xKVQWT2CLwN8+TDBsCK3+JWmEE=
git.haelnorr.com/h/golib/hws v0.5.0/go.mod h1:dxAbbGGNzqLXhZXwgt091QsvsPBdrS+1YsNQNldNVoM= git.haelnorr.com/h/golib/hws v0.6.0/go.mod h1:iAjdrwYZye2nsvbBGIMzVcfydV4F47qUp10MvimVCOY=
git.haelnorr.com/h/golib/hwsauth v0.6.1 h1:3BiM6hwuYDjgfu02hshvUtr592DnWi9Epj//3N13ti0= git.haelnorr.com/h/golib/hwsauth v0.7.0 h1:2uR7douZfkJ1vORUpvtS50FgGNm0GextDyMlCtrStbo=
git.haelnorr.com/h/golib/hwsauth v0.6.1/go.mod h1:xPdxqHzr1ZU0MHlG4o8r1zEstBu4FJCdaA0ZHSFxmKA= 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 h1:1Adxt9H3Y4fWFvFjWpvg/vSFhbgCMDMxgiE3m7KvDMI=
git.haelnorr.com/h/golib/jwt v0.10.1/go.mod h1:fbuPrfucT9lL0faV5+Q5Gk9WFJxPlwzRPpbMQKYZok4= 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= git.haelnorr.com/h/golib/notify v0.1.0 h1:xdf6zd21F6n+SuGTeJiuLNMf6zFXMvwpKD0gmNq8N10=

View File

@@ -36,7 +36,7 @@ func GetConfig(flags *Flags) (*Config, *ezconf.ConfigLoader, error) {
} }
loader := ezconf.New() loader := ezconf.New()
err = loader.RegisterIntegrations( err = loader.AddIntegrations(
hlog.NewEZConfIntegration(), hlog.NewEZConfIntegration(),
hws.NewEZConfIntegration(), hws.NewEZConfIntegration(),
hwsauth.NewEZConfIntegration(), hwsauth.NewEZConfIntegration(),

View File

@@ -6,16 +6,14 @@ import (
) )
type Config struct { type Config struct {
User string // ENV DB_USER: Database user for authentication (required) User string `ezconf:"DB_USER,required,description:Database user for authentication"`
Password string // ENV DB_PASSWORD: Database password for authentication (required) Password string `ezconf:"DB_PASSWORD,required,description:Database password for authentication"`
Host string // ENV DB_HOST: Database host address (required) Host string `ezconf:"DB_HOST,required,description:Database host address"`
Port uint16 // ENV DB_PORT: Database port (default: 5432) Port uint16 `ezconf:"DB_PORT,default:5432,description:Database port"`
DB string // ENV DB_NAME: Database name to connect to (required) DB string `ezconf:"DB_NAME,required,description:Database to connect to"`
SSL string // ENV DB_SSL: SSL mode for connection (default: disable) SSL string `ezconf:"DB_SSL,default:disable,description:SSL Mode"`
BackupDir string `ezconf:"DB_BACKUP_DIR,default:backups,description:Directory for database backups"`
// Backup configuration BackupRetention int `ezconf:"DB_BACKUP_RETENTION,default:10,description:Number of backups to keep"`
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)
} }
func ConfigFromEnv() (any, error) { func ConfigFromEnv() (any, error) {

View File

@@ -1,41 +1,11 @@
package db package db
import ( import (
"runtime" "git.haelnorr.com/h/golib/ezconf"
"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
}
// NewEZConfIntegration creates a new EZConf integration helper // NewEZConfIntegration creates a new EZConf integration helper
func NewEZConfIntegration() EZConfIntegration { func NewEZConfIntegration() *ezconf.Integration {
return EZConfIntegration{name: "DB", configFunc: ConfigFromEnv} return ezconf.NewIntegration("db", "DB", &Config{},
func() (any, error) { return ConfigFromEnv() })
} }

View File

@@ -9,12 +9,13 @@ import (
) )
type Config struct { type Config struct {
ClientID string // ENV DISCORD_CLIENT_ID: Discord application client ID (required) ClientID string `ezconf:"DISCORD_CLIENT_ID,required,description:Discord application client ID"`
ClientSecret string // ENV DISCORD_CLIENT_SECRET: Discord application client secret (required) 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 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)
} }
func ConfigFromEnv() (any, error) { func ConfigFromEnv() (any, error) {

View File

@@ -1,41 +1,11 @@
package discord package discord
import ( import (
"runtime" "git.haelnorr.com/h/golib/ezconf"
"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
}
// NewEZConfIntegration creates a new EZConf integration helper // NewEZConfIntegration creates a new EZConf integration helper
func NewEZConfIntegration() EZConfIntegration { func NewEZConfIntegration() *ezconf.Integration {
return EZConfIntegration{name: "Discord", configFunc: ConfigFromEnv} return ezconf.NewIntegration("discord", "Discord", &Config{},
func() (any, error) { return ConfigFromEnv() })
} }

View File

@@ -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"); @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 properties;
@layer theme, base, components, utilities; @layer theme, base, components, utilities;
@@ -248,6 +248,12 @@
.inset-0 { .inset-0 {
inset: calc(var(--spacing) * 0); inset: calc(var(--spacing) * 0);
} }
.start {
inset-inline-start: var(--spacing);
}
.end {
inset-inline-end: var(--spacing);
}
.end-0 { .end-0 {
inset-inline-end: calc(var(--spacing) * 0); inset-inline-end: calc(var(--spacing) * 0);
} }

View File

@@ -8,7 +8,7 @@ import (
) )
type Config struct { 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) { func ConfigFromEnv() (any, error) {

View File

@@ -1,41 +1,11 @@
package rbac package rbac
import ( import (
"runtime" "git.haelnorr.com/h/golib/ezconf"
"strings"
) )
// EZConfIntegration provides integration with ezconf for automatic configuration // NewEZConfIntegration creates a new EZConf integration
type EZConfIntegration struct { func NewEZConfIntegration() *ezconf.Integration {
configFunc func() (any, error) return ezconf.NewIntegration("rbac", "RBAC", &Config{},
name string func() (any, error) { return ConfigFromEnv() })
}
// 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}
} }

View File

@@ -7,7 +7,7 @@ import (
) )
type Config struct { 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) { func ConfigFromEnv() (any, error) {

View File

@@ -1,41 +1,11 @@
package oauth package oauth
import ( import (
"runtime" "git.haelnorr.com/h/golib/ezconf"
"strings"
) )
// EZConfIntegration provides integration with ezconf for automatic configuration // NewEZConfIntegration creates a new EZConf integration
type EZConfIntegration struct { func NewEZConfIntegration() *ezconf.Integration {
configFunc func() (any, error) return ezconf.NewIntegration("oauth", "OAuth", &Config{},
name string func() (any, error) { return ConfigFromEnv() })
}
// 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}
} }

View File

@@ -7,8 +7,8 @@ import (
) )
type Config struct { type Config struct {
Environment string // ENV SLAPSHOT_ENVIRONMENT: API environment to connect to (default: staging) Environment string `ezconf:"SLAPSHOT_ENVIRONMENT,default:staging,description:API environment to connect to"`
Key string // ENV SLAPSHOT_API_KEY: API Key for authorisation with the API (required) Key string `ezconf:"SLAPSHOT_API_KEY,required,description:API Key for authorisation with the API"`
} }
func ConfigFromEnv() (any, error) { func ConfigFromEnv() (any, error) {

View File

@@ -1,41 +1,9 @@
package slapshotapi package slapshotapi
import ( import "git.haelnorr.com/h/golib/ezconf"
"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
}
// NewEZConfIntegration creates a new EZConf integration helper // NewEZConfIntegration creates a new EZConf integration helper
func NewEZConfIntegration() EZConfIntegration { func NewEZConfIntegration() *ezconf.Integration {
return EZConfIntegration{name: "SlapshotAPI", configFunc: ConfigFromEnv} return ezconf.NewIntegration("slapshotapi", "SlapshotAPI", &Config{},
func() (any, error) { return ConfigFromEnv() })
} }