Documentation
¶
Overview ¶
Package base keeps the generic Handler. It's not intended to be used independently. Other handlers should be defined based on this handler
Index ¶
- func AnyRoute(handler Interface) error
- type Handler
- func (c *Handler) AddDepByService(dep *clientConfig.Client) error
- func (c *Handler) AddedDepByService(id string) bool
- func (c *Handler) Config() *config.Handler
- func (c *Handler) DepIds() []string
- func (c *Handler) IsRouteExist(command string) bool
- func (c *Handler) Route(cmd string, handle any, depIds ...string) error
- func (c *Handler) RouteCommands() []string
- func (c *Handler) SetConfig(handler *config.Handler)
- func (c *Handler) SetLogger(parent *log.Logger) error
- func (c *Handler) Start() error
- func (c *Handler) StartInstanceManager() error
- func (c *Handler) Status() string
- func (c *Handler) Type() config.HandlerType
- type Interface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
type Handler struct { Routes key_value.KeyValue RouteDeps key_value.KeyValue DepClients key_value.KeyValue Frontend *frontend.Frontend InstanceManager *instance_manager.Parent Manager *handler_manager.HandlerManager // contains filtered or unexported fields }
The Handler is the socket wrapper for the zeromq socket.
func (*Handler) AddDepByService ¶
func (c *Handler) AddDepByService(dep *clientConfig.Client) error
AddDepByService adds the config of the dependency. Intended to be called by Service not by developer
func (*Handler) AddedDepByService ¶
AddedDepByService returns true if the configuration exists
func (*Handler) IsRouteExist ¶
IsRouteExist returns true if the given route exists
func (*Handler) RouteCommands ¶
RouteCommands returns list of all route commands
func (*Handler) SetConfig ¶
SetConfig adds the parameters of the handler from the config.
Sets Frontend configuration as well.
func (*Handler) SetLogger ¶
SetLogger sets the logger (depends on context).
Creates instance Manager.
Creates handler Manager.
func (*Handler) Start ¶
Start the handler directly, not by goroutine. Will call the start function of each part.
func (*Handler) StartInstanceManager ¶
StartInstanceManager starts the instance Manager and listens to its events
func (*Handler) Type ¶
func (c *Handler) Type() config.HandlerType
Type returns the handler type. If the configuration is not set, returns config.UnknownType.
type Interface ¶
type Interface interface { Config() *config.Handler // SetConfig adds the parameters of the handler from the Config SetConfig(*config.Handler) // SetLogger adds the logger. The function accepts a parent, and function derives handler logger // Requires configuration to be set first SetLogger(*log.Logger) error // IsRouteExist returns true if the command is registered IsRouteExist(string) bool // RouteCommands returns list of all commands in this handler RouteCommands() []string // AddDepByService adds the Config of the extension that the handler depends on. // This function is intended to be called by the service. // // If any route does not require the dependency, it returns an error. // If the configuration already added, it returns an error. AddDepByService(*clientConfig.Client) error // AddedDepByService returns true if the configuration already exists AddedDepByService(string) bool // DepIds return the list of dep ids collected from all Routes. DepIds() []string // Route adds a new route and it's handlers for this handler Route(string, any, ...string) error // Type returns the type of the handler Type() config.HandlerType Start() error // The Status is empty is the handler is running. // Returns an error string if the Manager is not running Status() string }
Interface of the handler. Any handlers must be based on this. All handlers have
The interface that it accepts is the *client.ClientSocket from the "github.com/ahmetson/client-lib" package.
handler.New(handler.Type) handler.SetConfig(Config) handler.Route("hello", onHello)
The service will call: AddDepByService