Refine shit a little more
This commit is contained in:
26
options.go
26
options.go
@@ -23,17 +23,17 @@ func init() {
|
||||
|
||||
type Options struct {
|
||||
DBPath string `env:"DB_PATH" default:"eve-pi.db" description:"Database file path"`
|
||||
Port string `env:"HTTP_SERVER_PORT" default:"3000" description:"HTTP server port"`
|
||||
Port string `env:"HTTP_SERVER_PORT" default:"3000" description:"HTTP server port"`
|
||||
|
||||
ClientID string `env:"ESI_CLIENT_ID" required:"true" description:"EVE SSO client ID"`
|
||||
RedirectURI string `env:"ESI_REDIRECT_URI" required:"true" description:"EVE SSO redirect URI"`
|
||||
ClientID string `env:"ESI_CLIENT_ID" description:"EVE SSO client ID"`
|
||||
RedirectURI string `env:"ESI_REDIRECT_URI" default:"http://localhost:3000/callback" description:"EVE SSO redirect URI"`
|
||||
Scopes []string `env:"ESI_SCOPES" default:"esi-planets.manage_planets.v1" description:"EVE SSO scopes (space-separated)"`
|
||||
|
||||
WebhookURL string `env:"WEBHOOK_URL" required:"true" description:"Webhook URL for notifications"`
|
||||
WebhookEmail string `env:"WEBHOOK_EMAIL" required:"true" description:"Webhook authentication email"`
|
||||
WebhookToken string `env:"WEBHOOK_TOKEN" required:"true" description:"Webhook authentication token"`
|
||||
WebhookURL string `env:"WEBHOOK_URL" description:"Webhook URL for notifications"`
|
||||
WebhookEmail string `env:"WEBHOOK_EMAIL" description:"Webhook authentication email"`
|
||||
WebhookToken string `env:"WEBHOOK_TOKEN" description:"Webhook authentication token"`
|
||||
|
||||
LogLevel string `env:"LOG_LEVEL" default:"info" description:"Logging level (debug, info, warning, error)"`
|
||||
LogLevel string `env:"LOG_LEVEL" default:"info" description:"Logging level (dump, trace, debug, info, warning, error)"`
|
||||
}
|
||||
|
||||
func LoadOptions() (Options, error) {
|
||||
@@ -56,16 +56,13 @@ func LoadOptions() (Options, error) {
|
||||
}
|
||||
|
||||
envValue := os.Getenv(envKey)
|
||||
required := field.Tag.Get("required") == "true"
|
||||
defaultValue := field.Tag.Get("default")
|
||||
|
||||
if envValue == "" {
|
||||
if required {
|
||||
if defaultValue == "" {
|
||||
return Options{}, fmt.Errorf("required environment variable %s is not set", envKey)
|
||||
}
|
||||
if defaultValue != "" {
|
||||
envValue = defaultValue
|
||||
}
|
||||
envValue = defaultValue
|
||||
}
|
||||
|
||||
// Set the field value based on its type
|
||||
@@ -111,12 +108,11 @@ func GenerateEnvExample() error {
|
||||
continue
|
||||
}
|
||||
|
||||
required := field.Tag.Get("required") == "true"
|
||||
defaultValue := field.Tag.Get("default")
|
||||
description := field.Tag.Get("description")
|
||||
|
||||
// Generate example value
|
||||
exampleValue := generateExampleValue(field.Name, envKey, defaultValue, required)
|
||||
exampleValue := generateExampleValue(field.Name, envKey, defaultValue)
|
||||
|
||||
content += fmt.Sprintf("# %s\n", description)
|
||||
content += fmt.Sprintf("%s=%s\n\n", envKey, exampleValue)
|
||||
@@ -132,7 +128,7 @@ func GenerateEnvExample() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func generateExampleValue(fieldName, envKey, defaultValue string, required bool) string {
|
||||
func generateExampleValue(fieldName, envKey, defaultValue string) string {
|
||||
// If there's a default value, use it
|
||||
if defaultValue != "" {
|
||||
return defaultValue
|
||||
|
||||
Reference in New Issue
Block a user