Test webhook
This commit is contained in:
9
main.go
9
main.go
@@ -7,11 +7,14 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
||||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||||
|
wh "go-eve-pi/webhook"
|
||||||
|
|
||||||
"github.com/fasthttp/router"
|
"github.com/fasthttp/router"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var webhook wh.Webhook
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
logger.InitFlag()
|
logger.InitFlag()
|
||||||
@@ -28,6 +31,8 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webhook = wh.NewZulipWebhook(options.ZulipURL, options.ZulipEmail, options.ZulipToken)
|
||||||
|
|
||||||
// Setup fasthttp router
|
// Setup fasthttp router
|
||||||
r := router.New()
|
r := router.New()
|
||||||
|
|
||||||
@@ -70,6 +75,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
webhook.Post("eve-pi", "test", "test")
|
||||||
|
}
|
||||||
|
|
||||||
// Listen for SIGINT and gracefully shut down the server
|
// Listen for SIGINT and gracefully shut down the server
|
||||||
sigCh := make(chan os.Signal, 1)
|
sigCh := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigCh, os.Interrupt)
|
signal.Notify(sigCh, os.Interrupt)
|
||||||
|
|||||||
69
options.go
69
options.go
@@ -21,11 +21,16 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
ClientID string
|
|
||||||
RedirectURI string
|
|
||||||
Scopes []string
|
|
||||||
DBPath string
|
DBPath string
|
||||||
Port string
|
Port string
|
||||||
|
|
||||||
|
ESIScopes []string
|
||||||
|
ESIRedirectURI string
|
||||||
|
ESIClientID string
|
||||||
|
|
||||||
|
WebhookURL string
|
||||||
|
WebhookEmail string
|
||||||
|
WebhookToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadOptions() (Options, error) {
|
func LoadOptions() (Options, error) {
|
||||||
@@ -34,33 +39,45 @@ func LoadOptions() (Options, error) {
|
|||||||
return Options{}, fmt.Errorf("error loading .env file: %w", err)
|
return Options{}, fmt.Errorf("error loading .env file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
clientID := os.Getenv("ESI_CLIENT_ID")
|
dbPath := getOrDefault("DB_PATH", "eve-pi.db")
|
||||||
if clientID == "" {
|
port := getOrDefault("HTTP_SERVER_PORT", "3000")
|
||||||
return Options{}, fmt.Errorf("ESI_CLIENT_ID is required in .env file")
|
|
||||||
}
|
clientID := getOrFatal("ESI_CLIENT_ID")
|
||||||
redirectURI := os.Getenv("ESI_REDIRECT_URI")
|
redirectURI := getOrFatal("ESI_REDIRECT_URI")
|
||||||
if redirectURI == "" {
|
rawScopes := getOrDefault("ESI_SCOPES", "esi-planets.manage_planets.v1")
|
||||||
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")
|
|
||||||
}
|
|
||||||
scopes := strings.Fields(rawScopes)
|
scopes := strings.Fields(rawScopes)
|
||||||
dbPath := os.Getenv("DB_PATH")
|
|
||||||
if dbPath == "" {
|
webhookUrl := getOrFatal("WEBHOOK_URL")
|
||||||
return Options{}, fmt.Errorf("DB_PATH is required in .env file")
|
webhookEmail := getOrFatal("WEBHOOK_EMAIL")
|
||||||
}
|
webhookToken := getOrFatal("WEBHOOK_TOKEN")
|
||||||
port := os.Getenv("HTTP_SERVER_PORT")
|
|
||||||
if port == "" {
|
|
||||||
return Options{}, fmt.Errorf("HTTP_SERVER_PORT is required in .env file")
|
|
||||||
}
|
|
||||||
|
|
||||||
return Options{
|
return Options{
|
||||||
ClientID: clientID,
|
|
||||||
RedirectURI: redirectURI,
|
|
||||||
Scopes: scopes,
|
|
||||||
DBPath: dbPath,
|
DBPath: dbPath,
|
||||||
Port: port,
|
Port: port,
|
||||||
|
|
||||||
|
ESIClientID: clientID,
|
||||||
|
ESIRedirectURI: redirectURI,
|
||||||
|
ESIScopes: scopes,
|
||||||
|
|
||||||
|
WebhookURL: webhookUrl,
|
||||||
|
WebhookEmail: webhookEmail,
|
||||||
|
WebhookToken: webhookToken,
|
||||||
}, nil
|
}, 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type WebhookMessage struct {
|
|||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebhookInterface defines the contract for webhook operations
|
// Webhook defines the contract for webhook operations
|
||||||
type WebhookInterface interface {
|
type Webhook interface {
|
||||||
Post(channel, topic, message string) error
|
Post(channel, topic, message string) error
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user