webhook

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeError          string = "Error"
	EventTypePlayerJoin     string = "PlayerJoin"
	EventTypePlayerLeave    string = "PlayerLeave"
	EventTypeContainerStart string = "ContainerStart"
	EventTypeContainerStop  string = "ContainerStop"
)

Variables

View Source
var (
	ErrEventNotAllowed = errors.New("event not allowed")
)

Functions

This section is empty.

Types

type Event

type Event interface {
	EventType() string
}

type EventContainerStart

type EventContainerStart struct {
	ProxyUID string `json:"proxyUid"`
}

func (EventContainerStart) EventType

func (event EventContainerStart) EventType() string

type EventContainerStop

type EventContainerStop struct {
	ProxyUID string `json:"proxyUid"`
}

func (EventContainerStop) EventType

func (event EventContainerStop) EventType() string

type EventError

type EventError struct {
	Error    string `json:"error"`
	ProxyUID string `json:"proxyUid"`
}

func (EventError) EventType

func (event EventError) EventType() string

type EventLog

type EventLog struct {
	EventType string    `json:"eventType"`
	Timestamp time.Time `json:"timestamp"`
	Event     Event     `json:"event"`
}

EventLog is the struct that will be send to the Webhook.URL

type EventPlayerJoin

type EventPlayerJoin struct {
	Username      string `json:"username"`
	RemoteAddress string `json:"remoteAddress"`
	TargetAddress string `json:"targetAddress"`
	ProxyUID      string `json:"proxyUid"`
}

func (EventPlayerJoin) EventType

func (event EventPlayerJoin) EventType() string

type EventPlayerLeave

type EventPlayerLeave struct {
	Username      string `json:"username"`
	RemoteAddress string `json:"remoteAddress"`
	TargetAddress string `json:"targetAddress"`
	ProxyUID      string `json:"proxyUid"`
}

func (EventPlayerLeave) EventType

func (event EventPlayerLeave) EventType() string

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient represents an interface for the Webhook to send events with.

type Webhook

type Webhook struct {
	ID         string
	HTTPClient HTTPClient
	URL        string
	EventTypes []string
}

Webhook can send a Event via POST Request to a specified URL. There are two ways to use a Webhook. You can directly call DispatchEvent or Serve to attach a channel to the Webhook.

func (Webhook) DispatchEvent

func (webhook Webhook) DispatchEvent(event Event) error

DispatchEvent wraps the given Event in an EventLog and marshals it into JSON before sending it in a POST Request to the Webhook.URL.

Jump to

Keyboard shortcuts

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