Documentation
¶
Overview ¶
Package apiservice provides a simple system to instantiate clients of the luIDS api.
This package is a work in progress and makes no API stability promises.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterBuilder ¶
RegisterBuilder registers a service builder for an api signature.
Types ¶
type Autoloader ¶
type Autoloader struct {
// contains filtered or unexported fields
}
Autoloader implements Discover using a lazy build.
func NewAutoloader ¶
func NewAutoloader(defs []ServiceDef, opt ...AutoloaderOption) *Autoloader
NewAutoloader creates a new Autoloader with service definitions.
func (*Autoloader) GetService ¶
func (a *Autoloader) GetService(id string) (Service, bool)
GetService implements Discover interface.
func (*Autoloader) ListServices ¶
func (a *Autoloader) ListServices() []string
ListServices implements Discover interface.
type AutoloaderOption ¶
type AutoloaderOption func(*autoOptions)
AutoloaderOption is used for Autoloader configuration.
func SetLogger ¶
func SetLogger(l yalogi.Logger) AutoloaderOption
SetLogger option allows set a custom logger.
type BuildFn ¶
type BuildFn func(def ServiceDef, logger yalogi.Logger) (Service, error)
BuildFn defines a function that constructs a service using a service definition.
type Discover ¶
type Discover interface {
// GetService by id, returning false if not available
GetService(id string) (Service, bool)
// ListServices returns the ids of services available
ListServices() []string
}
Discover interface used for service discovering.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores service items indexed by an id. Implements Discover interface.
func (*Registry) GetService ¶
GetService implements Discover interface.
func (*Registry) ListServices ¶
ListServices implements Discover interface.
type Service ¶
type Service interface {
// API returns signature
API() string
// Close client
Close() error
// Ping status
Ping() error
}
Service is the interface that must be implemented by service API clients.
type ServiceDef ¶
type ServiceDef struct {
// ID must exist and be unique for its correct operation
ID string `json:"id"`
// Disabled
Disabled bool `json:"disabled,omitempty"`
// API defines the api implemented by the service
API string `json:"api"`
// Endpoint url
Endpoint string `json:"endpoint"`
// Client configuration
Client *grpctls.ClientCfg `json:"client,omitempty"`
// Enable log
Log bool `json:"log,omitempty"`
// Enable metrics
Metrics bool `json:"metrics,omitempty"`
// Enable cache
Cache bool `json:"cache,omitempty"`
// Opts stores custom fields
Opts map[string]interface{} `json:"opts,omitempty"`
}
ServiceDef is used for define and construct microservices
func ServiceDefsFromFile ¶
func ServiceDefsFromFile(path string) ([]ServiceDef, error)
ServiceDefsFromFile reads from file a slice of ServiceDef.
func (ServiceDef) ClientCfg ¶
func (def ServiceDef) ClientCfg() grpctls.ClientCfg
ClientCfg returns a copy of client configuration. It returns an empty struct if a null pointer is stored.