behavior

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 8 Imported by: 13

Documentation

Overview

Package behavior provides dynamic lookup of functions for handling events like receiving messages and for setting up and running stuff like actors.

Index

Constants

This section is empty.

Variables

View Source
var LoadRegistry = reg.LoadRegistry
View Source
var Quit = Message{Action: "quit"}

Functions

func FormatTimestamp added in v0.1.8

func FormatTimestamp(t time.Time) string

Types

type ActionHandler

type ActionHandler = func(*Context, m.Map, *Message)

type Address added in v0.1.8

type Address struct {
	Service     string `json:"service,omitempty"`
	Session     string `json:"session,omitempty"`
	Interaction string `json:"interaction,omitempty"`
}

type Context

type Context struct {
	Name      string
	Home      string
	Config    m.Map
	State     ContextState
	Logger    Logger
	Parent    *Context
	Self      chan Message
	DoneCh    chan struct{}
	WaitGroup *sync.WaitGroup
	Services  map[string]*Context
	Errors    []error
	ForgeEnv  *forge.ForgeEnv
}

func ChildContext

func ChildContext(pctx *Context, conf m.Map, name string) *Context

func RootContext

func RootContext(home string, conf m.Map, logger Logger, name string) *Context

func (Context) Deadline

func (ctx Context) Deadline() (deadline time.Time, ok bool)

func (Context) Done

func (ctx Context) Done() <-chan struct{}

func (Context) Err

func (ctx Context) Err() error

func (*Context) GetHandler

func (ctx *Context) GetHandler(name string) Handler

func (*Context) GetStep

func (ctx *Context) GetStep() Step

func (*Context) HandleAction

func (ctx *Context) HandleAction(spec m.Map, msg *Message)

func (*Context) HandleDone

func (ctx *Context) HandleDone() bool

func (*Context) HandleMsg

func (ctx *Context) HandleMsg(msg *Message) bool

func (*Context) HandleSpec

func (ctx *Context) HandleSpec(spec m.Map) bool

func (*Context) Log

func (ctx *Context) Log(lvl l.Level, txt string, fields m.Map)

func (*Context) LogCatch

func (ctx *Context) LogCatch(txt string) interface{}

func (*Context) LogDebug

func (ctx *Context) LogDebug(txt string, fields m.Map)

func (*Context) LogErr

func (ctx *Context) LogErr(txt string, fields m.Map)

func (*Context) LogInfo

func (ctx *Context) LogInfo(txt string, fields m.Map)

func (*Context) LogTrace

func (ctx *Context) LogTrace(txt string, fields m.Map)

func (*Context) LogWarn

func (ctx *Context) LogWarn(txt string, fields m.Map)

func (*Context) Msg

func (ctx *Context) Msg(par ...string) msgCtx

func (*Context) Run

func (ctx *Context) Run(fct func())

func (*Context) RunAction added in v0.1.9

func (ctx *Context) RunAction(fct ActionHandler, spec m.Map, msg *Message)

func (*Context) RunListener

func (ctx *Context) RunListener()

func (*Context) RunMsg

func (ctx *Context) RunMsg(fct MsgProc, msg *Message)

func (*Context) RunProc

func (ctx *Context) RunProc(fct Proc)

func (*Context) Send

func (ctx *Context) Send(msg *Message, svcName string)

func (*Context) SendAddr added in v0.1.8

func (ctx *Context) SendAddr(msg *Message, addr Address)

SendAddr is deprecated, use SendToAddr instead.

func (*Context) SendToAddr added in v0.1.13

func (ctx *Context) SendToAddr(msg *Message, addr Address)

func (*Context) SendToMailbox added in v0.1.13

func (ctx *Context) SendToMailbox(mb Mailbox, msg *Message)

SendToMailbox is a wrapper around the standard <- operator for sending a message via a channel. The context on which this method is called should be that of the receiver so that information about channel capacity handling can be retrieved.

func (*Context) Setup added in v0.1.19

func (ctx *Context) Setup()

func (*Context) Startup

func (ctx *Context) Startup()

func (Context) Value

func (ctx Context) Value(key interface{}) interface{}

func (*Context) WrappedFromJson added in v0.1.8

func (ctx *Context) WrappedFromJson(jsstr string) *WrappedMessage

type ContextState added in v0.1.8

type ContextState interface {
	GetSession(string) Session
}

type DefaultState added in v0.1.8

type DefaultState struct{}

func (*DefaultState) GetSession added in v0.1.19

func (st *DefaultState) GetSession(sid string) Session

type DummyHandler

type DummyHandler = func(*Context) bool

type HSpecs

type HSpecs = reg.HSpecs

delegations to go-schema/registry:

type Handler

type Handler = reg.Handler

type Logger

type Logger = l.ILogger

type Mailbox added in v0.1.19

type Mailbox chan Message

type Message

type Message struct {
	Domain  string  `json:"domain,omitempty"`
	Action  string  `json:"action,omitempty"`
	Class   string  `json:"class,omitempty"`
	Item    string  `json:"item,omitempty"`
	Sender  Address `json:"sender"`
	Payload Payload `json:"payload,omitempty"`
}

func (*Message) GetPayload

func (msg *Message) GetPayload(ctx *Context) m.Map

func (*Message) SetPayload added in v0.1.13

func (msg *Message) SetPayload(ctx *Context, data m.Map)

func (*Message) SetTimestampInPayload added in v0.1.15

func (msg *Message) SetTimestampInPayload(ctx *Context, ts *Timestamp)

func (*Message) Wrapped added in v0.1.8

func (msg *Message) Wrapped() *WrappedMessage

type MsgCtx

type MsgCtx = msgCtx

type MsgHandler

type MsgHandler = func(*Context, *Message) bool

type MsgProc

type MsgProc = func(*Context, *Message)

type Payload

type Payload string

func (Payload) JSONToMap added in v0.1.15

func (pl Payload) JSONToMap(ctx *Context) m.Map

type Proc

type Proc = func(*Context)

type Session added in v0.1.19

type Session interface {
	Send(ctx *Context, msg *Message)
}

type SpecHandler

type SpecHandler = func(*Context, m.Map) bool

type Step

type Step = func(*Context) bool

type Timestamp added in v0.1.8

type Timestamp time.Time

func GetTimestamp added in v0.1.15

func GetTimestamp(data m.Map, key string) *Timestamp

func GetTimestampDef added in v0.1.15

func GetTimestampDef(data m.Map, key string, def *Timestamp) *Timestamp

func (*Timestamp) AsTime added in v0.1.15

func (t *Timestamp) AsTime() *time.Time

func (*Timestamp) MarshalText added in v0.1.8

func (t *Timestamp) MarshalText() ([]byte, error)

func (*Timestamp) Unix added in v0.1.8

func (t *Timestamp) Unix() int64

func (*Timestamp) UnmarshalText added in v0.1.8

func (t *Timestamp) UnmarshalText(data []byte) error

type WrappedMessage added in v0.1.8

type WrappedMessage struct {
	Message   *Message  `json:"message"`
	Timestamp Timestamp `json:"timestamp"`
}

func (*WrappedMessage) Json added in v0.1.8

func (wm *WrappedMessage) Json(ctx *Context) string

Jump to

Keyboard shortcuts

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