base

package
v0.0.0-...-12a776e Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: MPL-2.0 Imports: 13 Imported by: 7

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyRoute

func AnyRoute(handler Interface) error

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 New

func New() *Handler

New handler

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

func (c *Handler) AddedDepByService(id string) bool

AddedDepByService returns true if the configuration exists

func (*Handler) Config

func (c *Handler) Config() *config.Handler

func (*Handler) DepIds

func (c *Handler) DepIds() []string

DepIds return the list of extension names required by this handler.

func (*Handler) IsRouteExist

func (c *Handler) IsRouteExist(command string) bool

IsRouteExist returns true if the given route exists

func (*Handler) Route

func (c *Handler) Route(cmd string, handle any, depIds ...string) error

Route adds a route along with its handler to this handler

func (*Handler) RouteCommands

func (c *Handler) RouteCommands() []string

RouteCommands returns list of all route commands

func (*Handler) SetConfig

func (c *Handler) SetConfig(handler *config.Handler)

SetConfig adds the parameters of the handler from the config.

Sets Frontend configuration as well.

func (*Handler) SetLogger

func (c *Handler) SetLogger(parent *log.Logger) error

SetLogger sets the logger (depends on context).

Creates instance Manager.

Creates handler Manager.

func (*Handler) Start

func (c *Handler) Start() error

Start the handler directly, not by goroutine. Will call the start function of each part.

func (*Handler) StartInstanceManager

func (c *Handler) StartInstanceManager() error

StartInstanceManager starts the instance Manager and listens to its events

func (*Handler) Status

func (c *Handler) Status() string

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

Jump to

Keyboard shortcuts

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