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

View File

@@ -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) {

View File

@@ -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() })
}