Test webhook
This commit is contained in:
77
options.go
77
options.go
@@ -21,11 +21,16 @@ func init() {
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
ClientID string
|
||||
RedirectURI string
|
||||
Scopes []string
|
||||
DBPath string
|
||||
Port string
|
||||
DBPath string
|
||||
Port string
|
||||
|
||||
ESIScopes []string
|
||||
ESIRedirectURI string
|
||||
ESIClientID string
|
||||
|
||||
WebhookURL string
|
||||
WebhookEmail string
|
||||
WebhookToken string
|
||||
}
|
||||
|
||||
func LoadOptions() (Options, error) {
|
||||
@@ -34,33 +39,45 @@ func LoadOptions() (Options, error) {
|
||||
return Options{}, fmt.Errorf("error loading .env file: %w", err)
|
||||
}
|
||||
|
||||
clientID := os.Getenv("ESI_CLIENT_ID")
|
||||
if clientID == "" {
|
||||
return Options{}, fmt.Errorf("ESI_CLIENT_ID is required in .env file")
|
||||
}
|
||||
redirectURI := os.Getenv("ESI_REDIRECT_URI")
|
||||
if redirectURI == "" {
|
||||
return Options{}, fmt.Errorf("ESI_REDIRECT_URI is required in .env file")
|
||||
}
|
||||
rawScopes := os.Getenv("ESI_SCOPES")
|
||||
if rawScopes == "" {
|
||||
return Options{}, fmt.Errorf("ESI_SCOPES is required in .env file")
|
||||
}
|
||||
dbPath := getOrDefault("DB_PATH", "eve-pi.db")
|
||||
port := getOrDefault("HTTP_SERVER_PORT", "3000")
|
||||
|
||||
clientID := getOrFatal("ESI_CLIENT_ID")
|
||||
redirectURI := getOrFatal("ESI_REDIRECT_URI")
|
||||
rawScopes := getOrDefault("ESI_SCOPES", "esi-planets.manage_planets.v1")
|
||||
scopes := strings.Fields(rawScopes)
|
||||
dbPath := os.Getenv("DB_PATH")
|
||||
if dbPath == "" {
|
||||
return Options{}, fmt.Errorf("DB_PATH is required in .env file")
|
||||
}
|
||||
port := os.Getenv("HTTP_SERVER_PORT")
|
||||
if port == "" {
|
||||
return Options{}, fmt.Errorf("HTTP_SERVER_PORT is required in .env file")
|
||||
}
|
||||
|
||||
webhookUrl := getOrFatal("WEBHOOK_URL")
|
||||
webhookEmail := getOrFatal("WEBHOOK_EMAIL")
|
||||
webhookToken := getOrFatal("WEBHOOK_TOKEN")
|
||||
|
||||
return Options{
|
||||
ClientID: clientID,
|
||||
RedirectURI: redirectURI,
|
||||
Scopes: scopes,
|
||||
DBPath: dbPath,
|
||||
Port: port,
|
||||
DBPath: dbPath,
|
||||
Port: port,
|
||||
|
||||
ESIClientID: clientID,
|
||||
ESIRedirectURI: redirectURI,
|
||||
ESIScopes: scopes,
|
||||
|
||||
WebhookURL: webhookUrl,
|
||||
WebhookEmail: webhookEmail,
|
||||
WebhookToken: webhookToken,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getOrFatal(key string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
logger.Error("Environment variable %s is required", key)
|
||||
os.Exit(1)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func getOrDefault(key, defaultValue string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user