event

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package event provides the event definition.

Index

Constants

This section is empty.

Variables

View Source
var (
	ActionNames = map[Action]string{
		ActionCreate: "Create",
		ActionRead:   "Read",
		ActionUpdate: "Update",
		ActionDelete: "Delete",
		ActionError:  "Error",
	}
)
View Source
var (
	KindNames = map[Kind]string{
		KindApplicationTrace:   "ApplicationTrace",
		KindApplicationLog:     "ApplicationLog",
		KindApplicationMetric:  "ApplicationMetric",
		KindKubernetesManifest: "KubernetesManifest",
		KindKubernetesLog:      "KubernetesLog",
		KindKubernetesMetric:   "KubernetesMetric",
	}
)

Functions

This section is empty.

Types

type Action

type Action uint8

Action represents the event action.

const (
	ActionInvalid Action = iota //
	ActionCreate
	ActionRead
	ActionUpdate
	ActionDelete
	ActionError
)

func ParseAction

func ParseAction(value string) Action

ParseAction parses the Action string.

func (Action) MarshalJSON

func (a Action) MarshalJSON() ([]byte, error)

MarshalJSON outputs the Action as a json.

func (Action) String

func (a Action) String() string

String outputs the Action as a string.

func (*Action) UnmarshalJSON

func (a *Action) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the Action from json.

func (Action) Validate

func (a Action) Validate() bool

Validate returns true if the Action is valid.

type Event

type Event struct {
	*Options `json:",inline"`
}

Event represents the event.

func NewEvent

func NewEvent(options *Options) *Event

NewEvent creates a new event.

type Kind

type Kind uint16

Kind represents the event topic.

const (
	KindInvalid Kind = iota //
	KindApplicationTrace
	KindApplicationLog
	KindApplicationMetric
	KindKubernetesManifest
	KindKubernetesLog
	KindKubernetesMetric
)

func ParseKind

func ParseKind(value string) Kind

ParseKind parses Kind from string.

func (Kind) MarshalJSON

func (k Kind) MarshalJSON() ([]byte, error)

MarshalJSON outputs the Kind as a json.

func (Kind) String

func (k Kind) String() string

String outputs the Kind as a string.

func (*Kind) UnmarshalJSON

func (k *Kind) UnmarshalJSON(data []byte) error

UnmarshalJSON parses Kind from json.

func (Kind) Validate

func (k Kind) Validate() bool

Validate returns true if the Kind is valid.

type Option

type Option func(o *Options)

Option represents the event option.

func WithAction

func WithAction(value Action) Option

WithAction sets the action for the event.

func WithAttributes

func WithAttributes(value types.Map[string]) Option

WithAttributes sets the attributes for the event.

func WithData

func WithData(value []byte) Option

WithData sets the data for the event.

func WithFormUrlEncodedData

func WithFormUrlEncodedData(value url.Values) Option

WithFormUrlEncodedData sets the form url encoded data for the event.

func WithHappen

func WithHappen(value types.DateTime) Option

WithHappen sets the happen for the event.

func WithID

func WithID(value string) Option

WithID sets the id for the event.

func WithJsonData

func WithJsonData(value any) Option

WithJsonData sets the json data for the event.

func WithKind

func WithKind(value Kind) Option

WithKind sets the kind for the event.

func WithMsgPackData

func WithMsgPackData(value any) Option

WithMsgPackData sets the msgpack data for the event.

func WithSchema

func WithSchema(value string) Option

WithSchema sets the schema for the event.

func WithSource

func WithSource(value string) Option

WithSource sets the source for the event.

func WithVersion

func WithVersion(value string) Option

WithVersion sets the version for the event.

func WithYamlData

func WithYamlData(value any) Option

WithYamlData sets the yaml data for the event.

type Options

type Options struct {
	ID         string            `json:"id"`
	Version    string            `json:"version"`
	Schema     types.URI         `json:"schema"`
	Source     types.URI         `json:"source"`
	Kind       Kind              `json:"kind"`
	Action     Action            `json:"action"`
	Attributes types.Map[string] `json:"attributes"`
	Data       []byte            `json:"data"`
	Happen     types.DateTime    `json:"happen"`
}

Options represents the event options.

func NewOptions

func NewOptions(options ...Option) *Options

NewOptions returns new options.

Jump to

Keyboard shortcuts

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