mirror of
https://github.com/h44z/wg-portal.git
synced 2025-09-15 07:11:15 +00:00
add simple webhook feature for peer, interface and user events (#398)
This commit is contained in:
48
internal/app/webhooks/model.go
Normal file
48
internal/app/webhooks/model.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package webhooks
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
// WebhookData is the data structure for the webhook payload.
|
||||
type WebhookData struct {
|
||||
// Event is the event type (e.g. create, update, delete)
|
||||
Event WebhookEvent `json:"event" example:"create"`
|
||||
|
||||
// Entity is the entity type (e.g. user, peer, interface)
|
||||
Entity WebhookEntity `json:"entity" example:"user"`
|
||||
|
||||
// Identifier is the identifier of the entity
|
||||
Identifier string `json:"identifier" example:"user-123"`
|
||||
|
||||
// Payload is the payload of the event
|
||||
Payload any `json:"payload"`
|
||||
}
|
||||
|
||||
// Serialize serializes the WebhookData to JSON and returns it as an io.Reader.
|
||||
func (d *WebhookData) Serialize() (io.Reader, error) {
|
||||
data, err := json.Marshal(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bytes.NewReader(data), nil
|
||||
}
|
||||
|
||||
type WebhookEntity = string
|
||||
|
||||
const (
|
||||
WebhookEntityUser WebhookEntity = "user"
|
||||
WebhookEntityPeer WebhookEntity = "peer"
|
||||
WebhookEntityInterface WebhookEntity = "interface"
|
||||
)
|
||||
|
||||
type WebhookEvent = string
|
||||
|
||||
const (
|
||||
WebhookEventCreate WebhookEvent = "create"
|
||||
WebhookEventUpdate WebhookEvent = "update"
|
||||
WebhookEventDelete WebhookEvent = "delete"
|
||||
)
|
Reference in New Issue
Block a user