webhook

package
v1.0.38 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxRetryAttempts is the ceiling on delivery attempts (initial try plus
	// retries) enforced both at configuration time and at delivery time.
	MaxRetryAttempts = maxRetryAttempts
)

Variables

This section is empty.

Functions

func ValidateTemplate

func ValidateTemplate(tmplStr string) error

Verifies a template string parses and produces valid JSON when rendered with sample data

Types

type Config

type Config struct {
	URL             string            `json:"url"`
	Secret          string            `json:"secret"`
	PayloadTemplate string            `json:"payload_template"`
	Headers         map[string]string `json:"headers"`
	MaxRetries      int               `json:"max_retries"`
	RetryDelayMs    int               `json:"retry_delay_ms"`
	TimeoutMs       int               `json:"timeout_ms"`
}

Controls a single webhook delivery - built from json config blob on webhook task

type Payload

type Payload struct {
	Event     string         `json:"event"`
	Timestamp time.Time      `json:"timestamp"`
	Server    *ServerPayload `json:"server,omitempty"`
	Data      map[string]any `json:"data,omitempty"`
}

Canonical event data fed into payload templates

func BuildPayload

func BuildPayload(event string, server *storage.Server, data map[string]any) *Payload

Assembles a Payload for the given event and server

type Result

type Result struct {
	Success      bool
	ResponseCode int
	ResponseBody string
	ErrorMessage string
	DurationMs   int64
	Attempts     int
}

A single delivery attempt outcome

func Deliver

func Deliver(ctx context.Context, cfg Config, payload *Payload) Result

Renders the payload, signs it, POSTs it, and retries on failure - returned res reflects final attempt made

type ServerPayload

type ServerPayload struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	Status     string `json:"status"`
	MCVersion  string `json:"mc_version"`
	ModLoader  string `json:"mod_loader"`
	Players    int    `json:"players_online"`
	MaxPlayers int    `json:"max_players"`
	Port       int    `json:"port"`
}

Server snapshot embedded in a webhook payload

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL