eventws

package
v0.17.23 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperationReloadStarted     = "reload.started"
	OperationReloadEnded       = "reload.ended"
	OperationDataUpdated       = "data.updated"
	OperationAttributesUpdated = "attributes.updated"
	OperationResult            = "result"
	OperationUpdated           = "updated"
	OperationCreated           = "created"
	OperationExecuted          = "executed"
)

Constants for known operations

View Source
const (
	ResourceTypeApp         = "app"
	ResourceTypeReload      = "reload"
	ResourceTypeEvaluation  = "evaluation"
	ResourceTypeItems       = "items"
	ResourceTypeSharingTask = "sharing-task"
)

Constants for known ResourceType

View Source
const BufferSize = 20
View Source
const WsType = "EventWebsocket"

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Operation    string                 `json:"operation,omitempty"`
	Origin       string                 `json:"origin,omitempty"`
	ResourceID   string                 `json:"resourceId,omitempty"`
	ResourceType string                 `json:"resourceType,omitempty"`
	Success      bool                   `json:"success,omitempty"`
	Time         string                 `json:"time,omitempty"`
	SpaceId      string                 `json:"spaceId,omitempty"`
	ReloadId     string                 `json:"reloadId,omitempty"`
	Data         map[string]interface{} `json:"data,omitempty"`
}

type EventFunc

type EventFunc struct {
	ID uint64
	// contains filtered or unexported fields
}

type EventHandler

type EventHandler struct {
	// contains filtered or unexported fields
}

EventHandler handles events received on event websocket

func NewEventHandler

func NewEventHandler() *EventHandler

NewEventHandler creates a new EventHandler which can be registered to and EventWs,

func (*EventHandler) DeRegisterFunc

func (handler *EventHandler) DeRegisterFunc(eventFunc *EventFunc)

DeRegisterFunc from execution on event triggering

func (*EventHandler) FakeEvent

func (handler *EventHandler) FakeEvent(event Event)

FakeEvent fake event being received

func (*EventHandler) RegisterFunc

func (handler *EventHandler) RegisterFunc(operation string, f func(event Event), replay bool) *EventFunc

RegisterFunc to be executed on event triggering replay: triggers the latest events from buffer upon creation

func (*EventHandler) RegisterFuncUntilCtxDone added in v0.7.0

func (handler *EventHandler) RegisterFuncUntilCtxDone(ctx context.Context, operations []string, replay bool, f func(event Event))

RegisterFuncUntilCtxDone to be executed on event triggering. The function is deregistered when context is done. replay: triggers the latest events from buffer upon creation

type EventWebsocket

type EventWebsocket struct {
	*EventHandler
	*wsdialer.WsDialer
}

func SetupEventSocket

func SetupEventSocket(dialContext context.Context, listenContext context.Context, timeout time.Duration, cookieJar http.CookieJar, trafficLogger TrafficLogger, metricsLogger TrafficMetricsLogger,
	url *neturl.URL, httpHeader http.Header, allowUntrusted bool, requestMetrics *requestmetrics.RequestMetrics, currentActionState func() *action.State) (*EventWebsocket, error)

SetupEventSocket to listen for events, event listening will stop at listenContext done.

type TrafficLogger

type TrafficLogger interface {
	Received([]byte)
	Opened()
}

type TrafficMetricsLogger

type TrafficMetricsLogger interface {
	SocketOpenMetric(url *neturl.URL, duration time.Duration)
}

Jump to

Keyboard shortcuts

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