leikari

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 12 Imported by: 0

README

leikari

actor framework for Golang

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorType        = reflect.TypeOf((*error)(nil)).Elem()
	ActorContextType = reflect.TypeOf((*ActorContext)(nil)).Elem()
	MessageType      = reflect.TypeOf((*Message)(nil)).Elem()
)
View Source
var (
	ErrUnknownCommand = Errorln("", "unknown command")
)

Functions

func CheckImplements

func CheckImplements(atype reflect.Type, btype reflect.Type) bool

func CheckImplementsOneOf

func CheckImplementsOneOf(atype reflect.Type, types ...reflect.Type) bool

func CheckIn

func CheckIn(ftype reflect.Type, params ...reflect.Type) bool

func CheckOut

func CheckOut(ftype reflect.Type, params ...reflect.Type) bool

func CompareType

func CompareType(atype reflect.Type, btype reflect.Type) bool

func IsActorContextType

func IsActorContextType(gtype reflect.Type) bool

func IsErrorType

func IsErrorType(gtype reflect.Type) bool

func IsMessageType

func IsMessageType(gtype reflect.Type) bool

func MethodByName

func MethodByName(v interface{}, name string) (reflect.Value, bool)

func PostStopFunc

func PostStopFunc(v interface{}) func(ActorContext) error

func PostStopMethod

func PostStopMethod(v interface{}) (reflect.Value, bool)

func PreStartFunc

func PreStartFunc(v interface{}) func(ActorContext) error

func PreStartMethod

func PreStartMethod(v interface{}) (reflect.Value, bool)

func PtrValue

func PtrValue(gvalue reflect.Value) reflect.Value

func ReceiveFunc

func ReceiveFunc(v interface{}) func(ActorContext, Message)

func ReceiveMethod

func ReceiveMethod(v interface{}) (reflect.Value, bool)

Types

type Actor

type Actor struct {
	OnReceive func(ActorContext, Message)
	OnStart   func(ActorContext) error
	OnStop    func(ActorContext) error
	Async     bool
}

func NewActor

func NewActor(v interface{}) Actor

func (Actor) AsyncActor

func (a Actor) AsyncActor() bool

func (Actor) PostStop

func (a Actor) PostStop(ctx ActorContext) error

func (Actor) PreStart

func (a Actor) PreStart(ctx ActorContext) error

func (Actor) Receive

func (a Actor) Receive(ctx ActorContext, msg Message)

type ActorContext

type ActorContext interface {
	ActorExecutor
	Name() string
	Log() Logger
	Settings() Settings
	Done() <-chan struct{}

	Self() Ref

	Handler() ActorHandler

	Set(string, interface{})
	Add(string, interface{}) error
	Replace(string, interface{}) error
	Get(string) (interface{}, bool)
}

type ActorExecutor

type ActorExecutor interface {
	Execute(Receiver, string, ...Option) (Ref, error)
}

type ActorHandler

type ActorHandler interface {
	Pusher
	ActorHandlerExecutor
	Name() string
	Close()

	Root() ActorHandler
	Parent() (ActorHandler, bool)
	Path() string
	System() System
	Log() Logger
	Settings() Settings

	Child(string) (ActorHandler, bool)
	Children() []ActorHandler

	CreateRef() Ref

	Cache() Cache
}

type ActorHandlerExecutor

type ActorHandlerExecutor interface {
	ExecuteHandler(Receiver, string, ...Option) (ActorHandler, error)
}

type ActorSettings

type ActorSettings interface {
	Settings

	WorkerPoolSize() int
	MessageQueueSize() int
	Async() bool
}

type AsyncActor

type AsyncActor interface {
	AsyncActor() bool
}

type Cache

type Cache interface {
	Set(key string, value interface{})
	Add(key string, value interface{}) error
	Replace(key string, value interface{}) error
	Get(key string) (interface{}, bool)
}

func NewCache

func NewCache() Cache

type DoneEvent

type DoneEvent struct{}

func Done

func Done() DoneEvent

type Error

type Error struct {
	Code        string `json:"code,omitempty"`
	Message     string `json:"error"`
	Description string `json:"description,omitempty"`
	Status      int    `json:"-"`
}

func Errorf

func Errorf(code string, format string, v ...interface{}) *Error

func Errorln

func Errorln(code string, v ...interface{}) *Error

func MapError

func MapError(code string, err error) *Error

func New

func New(code string, msg string) *Error

func NewOf

func NewOf(code string, err error) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) StatusCode

func (e *Error) StatusCode() int

func (*Error) String

func (e *Error) String() string

func (*Error) WithDescription

func (e *Error) WithDescription(desc string) *Error

func (*Error) WithStatusCode

func (e *Error) WithStatusCode(status int) *Error

type LogLevel

type LogLevel int
const (
	LEVEL_DEBUG LogLevel = iota
	LEVEL_INFO
	LEVEL_WARN
	LEVEL_ERROR
	LEVEL_FATAL
	LEVEL_PANIC
)

type Logger

type Logger interface {
	ForName(string) Logger

	Debug(...interface{})
	Info(...interface{})
	Warn(...interface{})
	Error(...interface{})
	Fatal(...interface{})
	Panic(...interface{})

	Debugf(string, ...interface{})
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})
	Fatalf(string, ...interface{})
	Panicf(string, ...interface{})
}

func Empty

func Empty() Logger

type Message

type Message interface {
	Value() interface{}
	Reply(interface{})
}

func Request

func Request(reply chan<- interface{}, v interface{}) Message

func Send

func Send(v interface{}) Message

type Option

type Option struct {
	Name  string
	Value interface{}
}

func Async

func Async() Option

func MessageQueue

func MessageQueue(size int) Option

func NoSignature

func NoSignature() Option

func WorkerPool

func WorkerPool(size int) Option

func (Option) Bool

func (opt Option) Bool() (bool, bool)

func (Option) Duration

func (opt Option) Duration() (time.Duration, bool)

func (Option) Float32

func (opt Option) Float32() (float32, bool)

func (Option) Float64

func (opt Option) Float64() (float64, bool)

func (Option) Int

func (opt Option) Int() (int, bool)

func (Option) Int16

func (opt Option) Int16() (int16, bool)

func (Option) Int32

func (opt Option) Int32() (int32, bool)

func (Option) Int64

func (opt Option) Int64() (int64, bool)

func (Option) Int8

func (opt Option) Int8() (int8, bool)

func (Option) String

func (opt Option) String() string

func (Option) Time

func (opt Option) Time() (time.Time, bool)

func (Option) Uint

func (opt Option) Uint() (uint, bool)

func (Option) Uint16

func (opt Option) Uint16() (uint16, bool)

func (Option) Uint32

func (opt Option) Uint32() (uint32, bool)

func (Option) Uint64

func (opt Option) Uint64() (uint64, bool)

func (Option) Uint8

func (opt Option) Uint8() (uint8, bool)

type Pusher added in v0.1.0

type Pusher interface {
	Push(Message) error
}

type Receiver

type Receiver interface {
	Receive(ActorContext, Message)
}

type ReceiverFunc

type ReceiverFunc func(ActorContext, Message)

func (ReceiverFunc) Receive

func (f ReceiverFunc) Receive(ctx ActorContext, msg Message)

type Ref

type Ref interface {
	Send(interface{}) error

	RequestChan(interface{}) <-chan interface{}
	Request(interface{}) (interface{}, error)
	RequestContext(context.Context, interface{}) (interface{}, error)
}

func NewRef added in v0.1.0

func NewRef(pusher Pusher) Ref

type ServiceExecutor

type ServiceExecutor interface {
	ExecuteService(Receiver, string, ...Option) (ActorHandler, error)
}

type Settings

type Settings interface {
	Get(string) interface{}
	GetBool(string) bool
	GetFloat64(string) float64
	GetInt(string) int
	GetIntSlice(string) []int
	GetString(string) string
	GetStringSlice(string) []string
	GetTime(string) time.Time
	GetDuration(string) time.Duration
	IsSet(string) bool

	GetDefault(string, interface{}) interface{}
	GetDefaultBool(string, bool) bool
	GetDefaultFloat64(string, float64) float64
	GetDefaultInt(string, int) int
	GetDefaultIntSlice(string, ...int) []int
	GetDefaultString(string, string) string
	GetDefaultStringSlice(string, ...string) []string
	GetDefaultTime(string, time.Time) time.Time
	GetDefaultDuration(string, time.Duration) time.Duration

	GetSub(string) Settings
}

type Startable

type Startable interface {
	PreStart(ActorContext) error
}

type Stopable

type Stopable interface {
	PostStop(ActorContext) error
}

type System

type System interface {
	ActorExecutor
	ServiceExecutor
	Settings() SystemSettings
	Log() Logger
	Terminate()
	Terminated() <-chan int
	Run()

	Timer(time.Duration, func(time.Time)) *time.Timer
	Ticker(time.Duration, func(time.Time)) *time.Ticker
}

func NewSystem

func NewSystem(opts ...Option) System

type SystemSettings

type SystemSettings interface {
	Settings

	NoSignature() bool
	GetActorSettings(string, ...Option) ActorSettings
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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