app

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	APP_BUILDING_OPT_SESSION_STATE_MANAGER = "WithSessionStateManager"
	APP_BUILDING_OPT_PROTOCOL_RESOLVER     = "WithProtocolResolver"
	APP_BUILDING_OPT_PROTOCOL_EMITTER      = "WithProtocolEmitter"

	APP_BUILDING_OPT_LOGGER_OUTPUT       = "WithLoggerOutput"
	APP_BUILDING_OPT_LOGGER_FLAGS        = "WithLoggerFlags"
	APP_BUILDING_OPT_TRACER_PROVIDER     = "WithTracerProvider"
	APP_BUILDING_OPT_TEXT_MAP_PROPAGATOR = "WithTextMapPropagator"

	APP_BUILDING_OPT_EVENT_CLIENT   = "WithEventClient"
	APP_BUILDING_OPT_MESSAGE_ROUTER = "WithMessageRouter"
	APP_BUILDING_OPT_EVENT_ROUTER   = "WithEventRouter"

	APP_BUILDING_OPT_INVALID_MESSAGE_HANDLER = "WithInvalidMessageHandler"
	APP_BUILDING_OPT_INVALID_EVENT_HANDLER   = "WithInvalidEventHandler"
	APP_BUILDING_OPT_DEFAULT_MESSAGE_HANDLER = "WithDefaultMessageHandler"
	APP_BUILDING_OPT_DEFAULT_EVENT_HANDLER   = "WithDefaultEventHandler"
	APP_BUILDING_OPT_ERROR_HANDLER           = "WithErrorHandler"
)
View Source
const (
	InvalidChannel string = "?"

	TAG_PROTOCOL       = "protocol"
	TAG_CHANNEL        = "channel"
	TAG_OPT_EXPAND_ENV = "@ExpandEnv"
	OPT_ON             = "on"
	OPT_OFF            = "off"
)
View Source
const (
	Nop                               = appError("Nop")
	ErrJoinClosedMessageClientManager = appError("Join() MessageClient with a stopped MessageClientManager")
	ErrSendMessageToClosedWriter      = appError("MessageClient send message to closed writer")
)

Variables

Functions

func StdProtocolEmitter

func StdProtocolEmitter(format MessageFormat, protocol string, payload []byte) []byte

Types

type AppBase added in v0.2.5

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

func (*AppBase) EnableStackTrace added in v0.2.5

func (app *AppBase) EnableStackTrace(enabled bool)

func (*AppBase) Logger added in v0.2.5

func (app *AppBase) Logger() *log.Logger

func (*AppBase) TextMapPropagator added in v0.2.5

func (app *AppBase) TextMapPropagator() propagation.TextMapPropagator

func (*AppBase) TracerProvider added in v0.2.5

func (app *AppBase) TracerProvider() *trace.SeverityTracerProvider

type Application

type Application struct {
	Name string
	// contains filtered or unexported fields
}

func Build

func Build(appName string, opts ...ApplicationBuildingOption) (*Application, error)

func Init

func Init(v Module, opts ...ModuleBindingOption) *Application

func (*Application) MessageClientManager

func (ap *Application) MessageClientManager() *MessageClientManager

func (*Application) SessionState added in v0.2.6

func (ap *Application) SessionState(id string) SessionState

func (*Application) Start

func (ap *Application) Start(ctx context.Context) error

func (*Application) Stop

func (ap *Application) Stop(ctx context.Context) error

func (*Application) TextMapPropagator

func (ap *Application) TextMapPropagator() propagation.TextMapPropagator

func (*Application) TracerProvider

func (ap *Application) TracerProvider() *trace.SeverityTracerProvider

type ApplicationBuildingOption

type ApplicationBuildingOption interface {
	// contains filtered or unexported methods
}

func WithDefaultEventHandler

func WithDefaultEventHandler(handler EventHandler) ApplicationBuildingOption

func WithDefaultMessageHandler

func WithDefaultMessageHandler(handler MessageHandler) ApplicationBuildingOption

func WithErrorHandler

func WithErrorHandler(handler ErrorHandler) ApplicationBuildingOption

func WithEventClient

func WithEventClient(source EventClient) ApplicationBuildingOption

func WithEventRouter

func WithEventRouter(router EventRouter) ApplicationBuildingOption

func WithInvalidEventHandler

func WithInvalidEventHandler(handler EventHandler) ApplicationBuildingOption

func WithInvalidMessageHandler

func WithInvalidMessageHandler(handler MessageHandler) ApplicationBuildingOption

func WithLoggerFlags

func WithLoggerFlags(flags int) ApplicationBuildingOption

func WithLoggerOutput added in v0.2.1

func WithLoggerOutput(w io.Writer) ApplicationBuildingOption

func WithMessageRouter

func WithMessageRouter(router MessageRouter) ApplicationBuildingOption

func WithProtocolEmitter

func WithProtocolEmitter(emitter ProtocolEmitter) ApplicationBuildingOption

func WithProtocolResolver

func WithProtocolResolver(resolver ProtocolResolver) ApplicationBuildingOption

func WithSessionStateManager

func WithSessionStateManager(manager SessionStateManager) ApplicationBuildingOption

type ApplicationWorker

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

type ClientIDValidator

type ClientIDValidator func(string) bool

type Context

type Context struct {
	SessionID    string
	SessionState SessionState
	GlobalState  SessionState
	// contains filtered or unexported fields
}

func (*Context) CloseSend added in v0.2.4

func (ctx *Context) CloseSend() error

func (*Context) Deadline

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

Deadline implements context.Context.

func (*Context) Done

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

Done implements context.Context.

func (*Context) Err

func (*Context) Err() error

Err implements context.Context.

func (*Context) Forward

func (ctx *Context) Forward(channel string, payload []byte)

func (*Context) InvalidEvent

func (ctx *Context) InvalidEvent(event *Event)

func (*Context) InvalidMessage

func (ctx *Context) InvalidMessage(message *Message)

func (*Context) IsCloseSend added in v0.2.4

func (ctx *Context) IsCloseSend() bool

func (*Context) Logger

func (ctx *Context) Logger() *log.Logger

func (*Context) Send

func (ctx *Context) Send(format MessageFormat, protocol string, body []byte) error

func (*Context) SetValue

func (ctx *Context) SetValue(key interface{}, value interface{})

func (*Context) Value

func (ctx *Context) Value(key any) any

Value implements context.Context.

type ErrorHandler

type ErrorHandler func(err error)

type Event

type Event struct {
	Channel  string
	Payload  []byte
	Delegate EventDelegate
	// contains filtered or unexported fields
}

func (*Event) Abort

func (e *Event) Abort()

func (*Event) Ack

func (e *Event) Ack()

func (*Event) Retry

func (e *Event) Retry()

type EventClient

type EventClient interface {
	Start(*EventPipe)
	Stop()
	Close() error

	EventForwarder
}

type EventDelegate

type EventDelegate interface {
	OnAck(event *Event)
	OnRetry(event *Event)
	OnAbort(event *Event)
}

type EventForwarder

type EventForwarder interface {
	Forward(channel string, payload []byte) error
}

type EventHandler

type EventHandler func(ctx *Context, event *Event) error

type EventPipe

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

func (*EventPipe) Error

func (pipe *EventPipe) Error(err error)

func (*EventPipe) Forward

func (pipe *EventPipe) Forward(event *Event)

type EventRouter

type EventRouter map[string]EventHandler

func (EventRouter) Add

func (r EventRouter) Add(channel string, handler EventHandler)

func (EventRouter) Get

func (r EventRouter) Get(channel string) EventHandler

func (EventRouter) Has

func (r EventRouter) Has(channel string) bool

func (EventRouter) Remove

func (r EventRouter) Remove(channel string)

type GenericApplicationBuildingOption added in v0.2.5

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

type LoggingWriter added in v0.2.5

type LoggingWriter struct {
	EnableStackTrace bool
	// contains filtered or unexported fields
}

func NewLoggingWriter added in v0.2.5

func NewLoggingWriter(writer io.Writer) *LoggingWriter

func (*LoggingWriter) Write added in v0.2.5

func (w *LoggingWriter) Write(p []byte) (n int, err error)

Write implements io.Writer.

func (*LoggingWriter) Writter added in v0.2.5

func (w *LoggingWriter) Writter() io.Writer

type Message

type Message struct {
	Format   MessageFormat
	Protocol string
	Body     []byte
}

func (*Message) DecodeContent

func (m *Message) DecodeContent(v MessageContent) error

func (Message) Equals

func (m Message) Equals(other Message) bool

type MessageClient

type MessageClient interface {
	Start(*MessagePipe)
	Stop()
	Close() error
	RegisterCloseHandler(func(MessageClient))

	MessageSender
	MessageClientInfoImpl
}

type MessageClientInfo added in v0.2.2

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

func NewMessageClientInfo added in v0.2.2

func NewMessageClientInfo() *MessageClientInfo

func (*MessageClientInfo) ID added in v0.2.2

func (info *MessageClientInfo) ID() string

ID implements MessageClientInfoImpl.

func (*MessageClientInfo) Logger added in v0.2.2

func (info *MessageClientInfo) Logger() *log.Logger

Logger implements MessageClientInfoImpl.

func (*MessageClientInfo) StartAt added in v0.2.2

func (info *MessageClientInfo) StartAt() time.Time

StartAt implements MessageClientInfoImpl.

type MessageClientInfoImpl added in v0.2.2

type MessageClientInfoImpl interface {
	ID() string
	StartAt() time.Time
	Logger() *log.Logger
	// contains filtered or unexported methods
}

type MessageClientManager

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

func (*MessageClientManager) Expel

func (manager *MessageClientManager) Expel(client MessageClient) error

func (*MessageClientManager) Join

func (manager *MessageClientManager) Join(client MessageClient) error

type MessageContent

type MessageContent interface {
	Decode(format MessageFormat, body []byte) error
	Encode() (MessageFormat, []byte)
	Validate() error
}

type MessageError

type MessageError error

type MessageFormat

type MessageFormat uint
const (
	UNKNOWN_MESSAGE MessageFormat = 0
	TEXT_MESSAGE    MessageFormat = 1
	BINARY_MESSAGE  MessageFormat = 2
	CLOSE_MESSAGE   MessageFormat = 8
	PING_MESSAGE    MessageFormat = 9
	PONG_MESSAGE    MessageFormat = 10
)

func (MessageFormat) IsControl

func (format MessageFormat) IsControl() bool

func (MessageFormat) IsData

func (format MessageFormat) IsData() bool

type MessageHandler

type MessageHandler func(ctx *Context, message *Message)

type MessagePipe

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

func (*MessagePipe) Error

func (pipe *MessagePipe) Error(err error)

func (*MessagePipe) Forward

func (pipe *MessagePipe) Forward(client MessageClient, message *Message)

type MessageRouter

type MessageRouter map[string]MessageHandler

func (MessageRouter) Add

func (r MessageRouter) Add(code string, handler MessageHandler)

func (MessageRouter) Get

func (r MessageRouter) Get(code string) MessageHandler

func (MessageRouter) Has

func (r MessageRouter) Has(code string) bool

func (MessageRouter) Remove

func (r MessageRouter) Remove(code string)

type MessageSender

type MessageSender interface {
	Send(format MessageFormat, payload []byte) error
}

type MessageSource

type MessageSource struct {
	Message *Message
	Client  MessageClient
}

type MessageWorker

type MessageWorker struct {
}

type Module

type Module interface {
	ModuleOptions() []ApplicationBuildingOption
}

type ModuleBindingOption

type ModuleBindingOption interface {
	// contains filtered or unexported methods
}

func BindConfig

func BindConfig(v interface{}) ModuleBindingOption

func BindEventClient

func BindEventClient(v interface{}) ModuleBindingOption

func BindServiceProvider

func BindServiceProvider(v interface{}) ModuleBindingOption

type ModuleBindingOptionFunc

type ModuleBindingOptionFunc func(reflect.Value, TargetValueRole) error

type ModuleOptionCollection

type ModuleOptionCollection []ApplicationBuildingOption

func (ModuleOptionCollection) ModuleOptions

type MultiEventClient

type MultiEventClient map[string]EventClient

func (MultiEventClient) Close

func (hub MultiEventClient) Close() error

Close implements EventBroker.

func (MultiEventClient) Forward

func (hub MultiEventClient) Forward(channel string, payload []byte) error

Forward implements EventBroker.

func (MultiEventClient) Start

func (hub MultiEventClient) Start(pipe *EventPipe)

Start implements EventBroker.

func (MultiEventClient) Stop

func (hub MultiEventClient) Stop()

Stop implements EventBroker.

type NoopEventClient

type NoopEventClient struct{}

func (NoopEventClient) Close

func (NoopEventClient) Close() error

Close implements EventSource.

func (NoopEventClient) Forward

func (NoopEventClient) Forward(channel string, payload []byte) error

Forward implements EventSource.

func (NoopEventClient) Start

func (NoopEventClient) Start(*EventPipe)

Start implements EventSource.

func (NoopEventClient) Stop

func (NoopEventClient) Stop()

Stop implements EventSource.

type ProtocolEmitter

type ProtocolEmitter func(format MessageFormat, protocol string, body []byte) []byte

type ProtocolResolver

type ProtocolResolver func(format MessageFormat, payload []byte) (string, []byte)

type RestrictedMessageClient added in v0.2.2

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

func NewRestrictedMessageClient added in v0.2.2

func NewRestrictedMessageClient(client MessageClient) *RestrictedMessageClient

func (*RestrictedMessageClient) Close added in v0.2.2

func (*RestrictedMessageClient) Close() error

Close implements MessageClient.

func (*RestrictedMessageClient) RegisterCloseHandler added in v0.2.2

func (*RestrictedMessageClient) RegisterCloseHandler(func(MessageClient))

RegisterCloseHandler implements MessageClient.

func (*RestrictedMessageClient) Start added in v0.2.2

Start implements MessageClient.

func (*RestrictedMessageClient) Stop added in v0.2.2

func (*RestrictedMessageClient) Stop()

Stop implements MessageClient.

type SessionState

type SessionState interface {
	CanVisit() bool
	Visit(func(k, v interface{}))
	Value(k interface{}) interface{}
	SetValue(k, v interface{})
	Lock()
	Unlock()
}

type SessionStateManager

type SessionStateManager interface {
	Load(id string) SessionState
	Update(id string, state SessionState)
	Delete(id string)
	TryCreate(id string) bool
}

type StdSessionState

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

func NewStdSessionState

func NewStdSessionState() *StdSessionState

func (*StdSessionState) CanVisit

func (state *StdSessionState) CanVisit() bool

CanVisit implements SessionState.

func (*StdSessionState) Lock

func (state *StdSessionState) Lock()

Lock implements SessionState.

func (*StdSessionState) SetValue

func (state *StdSessionState) SetValue(k interface{}, v interface{})

SetValue implements SessionState.

func (*StdSessionState) Unlock

func (state *StdSessionState) Unlock()

Unlock implements SessionState.

func (*StdSessionState) Value

func (state *StdSessionState) Value(k interface{}) interface{}

Value implements SessionState.

func (*StdSessionState) Visit

func (state *StdSessionState) Visit(fn func(k interface{}, v interface{}))

Visit implements SessionState.

type StdSessionStateManager

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

func NewStdSessionStateManager

func NewStdSessionStateManager() *StdSessionStateManager

func (*StdSessionStateManager) Delete

func (m *StdSessionStateManager) Delete(id string)

Delete implements SessionStateManager.

func (*StdSessionStateManager) Load

Load implements SessionStateManager.

func (*StdSessionStateManager) TryCreate

func (m *StdSessionStateManager) TryCreate(id string) bool

TryCreate implements SessionStateManager.

func (*StdSessionStateManager) Update

func (m *StdSessionStateManager) Update(id string, state SessionState)

Update implements SessionStateManager.

type TargetValueRole

type TargetValueRole string
const (
	APP            TargetValueRole = "APP"
	MODULE_OPTIONS TargetValueRole = "MODULE_OPTIONS"
)

Jump to

Keyboard shortcuts

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