updated ezconf
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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() })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user