component

package
v3.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct{}

Base implements a default component for Component.

func (*Base) AfterInit

func (c *Base) AfterInit()

AfterInit was called after the component is initialized.

func (*Base) BeforeShutdown

func (c *Base) BeforeShutdown()

BeforeShutdown was called before the component to shutdown.

func (*Base) Init

func (c *Base) Init()

Init was called to initialize the component.

func (*Base) Shutdown

func (c *Base) Shutdown()

Shutdown was called to shutdown the component.

type Component

type Component interface {
	Init()
	AfterInit()
	BeforeShutdown()
	Shutdown()
}

Component is the interface that represent a component.

type Handler

type Handler struct {
	Receiver    reflect.Value  // receiver of method
	Method      reflect.Method // method stub
	Type        reflect.Type   // low-level type of method
	IsRawArg    bool           // whether the data need to serialize
	MessageType message.Type   // handler allowed message type (either request or notify)
}

Handler represents a message.Message's handler's meta information.

func (*Handler) ValidateMessageType

func (h *Handler) ValidateMessageType(msgType message.Type) (exitOnError bool, err error)

ValidateMessageType validates a given message type against the handler's one and returns an error if it is a mismatch and a boolean indicating if the caller should exit in the presence of this error or not.

type Option

type Option func(options *options)

Option used to customize handler

func WithName

func WithName(name string) Option

WithName used to rename component name

func WithNameFunc

func WithNameFunc(fn func(string) string) Option

WithNameFunc override handler name by specific function such as: strings.ToUpper/strings.ToLower

type Remote

type Remote struct {
	Receiver reflect.Value  // receiver of method
	Method   reflect.Method // method stub
	HasArgs  bool           // if remote has no args we won't try to serialize received data into arguments
	Type     reflect.Type   // low-level type of method
}

Remote represents remote's meta information.

type Service

type Service struct {
	Name     string              // name of service
	Type     reflect.Type        // type of the receiver
	Receiver reflect.Value       // receiver of methods for the service
	Handlers map[string]*Handler // registered methods
	Remotes  map[string]*Remote  // registered remote methods
	Options  options             // options
}

Service implements a specific service, some of it's methods will be called when the correspond events is occurred.

func NewService

func NewService(comp Component, opts []Option) *Service

NewService creates a new service

func (*Service) ExtractHandler

func (s *Service) ExtractHandler() error

ExtractHandler extract the set of methods from the receiver value which satisfy the following conditions: - exported method of exported type - one or two arguments - the first argument is context.Context - the second argument (if it exists) is []byte or a pointer - zero or two outputs - the first output is [] or a pointer - the second output is an error

func (*Service) ExtractRemote

func (s *Service) ExtractRemote() error

ExtractRemote extract the set of methods from the receiver value which satisfy the following conditions: - exported method of exported type - two return values - the first return implements protobuf interface - the second return is an error

Jump to

Keyboard shortcuts

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