behavior

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: MIT Imports: 6 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 Quit = Message{Action: "quit"}

Functions

func FormatTimestamp added in v0.1.8

func FormatTimestamp(t time.Time) string

func LoadRegistry

func LoadRegistry(uname string, specs HSpecs)

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"`
}

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
}

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, err 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)

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 {
	GetSessionMailbox(string) chan Message
}

type DefaultState added in v0.1.8

type DefaultState struct{}

func (*DefaultState) GetSessionMailbox added in v0.1.8

func (st *DefaultState) GetSessionMailbox(sid string) chan Message

type DummyHandler

type DummyHandler = func(*Context) bool

type HSpecs

type HSpecs []struct {
	FName    string
	Function Handler
}

type Handler

type Handler interface{}

func GetHandler

func GetHandler(uname, fname string) Handler

type Logger

type Logger interface {
	Log(l.Level, string, m.Map)
	GetMaxLevel() l.Level
	SetMaxLevel(l.Level)
}

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) GetSenderMailbox added in v0.1.9

func (msg *Message) GetSenderMailbox(ctx *Context) chan Message

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

type Proc

type Proc = func(*Context)

type Registry

type Registry map[string]unit

func (Registry) Add

func (reg Registry) Add(uname string, fname string, hdlr Handler)

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 (*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