123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package main
- import (
- "context"
- "fmt"
- "log"
- "time"
- "git.linuxforward.com/byom/byom-golang-lib/pkg/webhook"
- )
- func main() {
- // Create webhook configuration
- cfg := webhook.Config{
- BaseURL: "https://api.example.com",
- Domain: "myapp.com",
- SecretKey: "your-secret-key",
- Timeout: 5 * time.Second,
- MaxRetries: 3,
- RetryBackoff: time.Second,
- }
- // Create new webhook client
- client, err := webhook.New(cfg)
- if err != nil {
- log.Fatalf("Failed to create webhook client: %v", err)
- }
- defer client.Close()
- // Create context with timeout
- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
- defer cancel()
- // Send webhook
- err = client.Send(ctx, "user@example.com", "user.created")
- if err != nil {
- log.Fatalf("Failed to send webhook: %v", err)
- }
- fmt.Println("Webhook sent successfully!")
- // Example of validating a webhook signature on the receiver side
- payload := []byte(`{"email":"user@example.com","domain":"myapp.com","action":"user.created"}`)
- signature := "computed-signature-from-request-header"
- isValid := webhook.ValidateSignature(payload, signature, cfg.SecretKey)
- fmt.Printf("Webhook signature is valid: %v\n", isValid)
- }
|