check / check (push) Waiting to run
Every reference from a model to the record it belongs to (a target's or entrypoint's webhook, a webhook's or API key's user, an event's webhook and entrypoint, a delivery's event and target, a delivery result's delivery) is now tagged json:"-", so a preloaded model can be marshalled without the encoder recursing between parent and child. References to child records stay. Tests marshal each of the nine references set, preloaded where it matters, and check the parent's id is absent, so deleting or restoring any one tag fails a test; preloading still fills each reference. Model: opus-5-5
42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package database
|
|
|
|
// TargetType represents the type of delivery target
|
|
type TargetType string
|
|
|
|
// Target type values.
|
|
const (
|
|
TargetTypeHTTP TargetType = "http"
|
|
TargetTypeDatabase TargetType = "database"
|
|
TargetTypeLog TargetType = "log"
|
|
TargetTypeSlack TargetType = "slack"
|
|
)
|
|
|
|
// Target represents a delivery target for a webhook
|
|
type Target struct {
|
|
BaseModel
|
|
|
|
WebhookID string `gorm:"type:uuid;not null" json:"webhookId"`
|
|
Name string `gorm:"not null" json:"name"`
|
|
Type TargetType `gorm:"not null" json:"type"`
|
|
Active bool `gorm:"default:true" json:"active"`
|
|
|
|
// Configuration fields (JSON stored based on type).
|
|
//
|
|
// json:"-" because the blob holds the target's credential — a
|
|
// Slack incoming-webhook URL, or an http destination whose path
|
|
// segments are the secret. delivery.TargetView is the masking
|
|
// barrier for the HTML path; this tag is the barrier for any
|
|
// handler that marshals the model itself.
|
|
Config string `gorm:"type:text" json:"-"` // JSON configuration
|
|
|
|
// For HTTP targets (max_retries=0 means fire-and-forget,
|
|
// >0 enables retries with backoff)
|
|
MaxRetries int `json:"maxRetries,omitempty"`
|
|
MaxQueueSize int `json:"maxQueueSize,omitempty"`
|
|
|
|
// Relations. No model marshals the record it belongs to:
|
|
// Webhook.Targets leads back here, and the JSON could loop.
|
|
Webhook Webhook `json:"-"`
|
|
Deliveries []Delivery `json:"deliveries,omitempty"`
|
|
}
|