Version: v3.0.0-beta.2 Latest Latest

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

Go to latest
Published: Feb 2, 2021 License: Apache-2.0 Imports: 22 Imported by: 1



Package catalog contains the core functionalities of service catalog and exposes functions and structs for service representation, processing, and storage



View Source
const (
	DNSSDServiceType = "_linksmart-sc._tcp"
	MaxPerPage       = 100
	LoggerPrefix     = "[sc] "

	CatalogBackendMemory  = "memory"
	CatalogBackendLevelDB = "leveldb"


	MaxServiceTTL = 2147483647 // in seconds i.e. 2^31 - 1 seconds or approx. 68 years, inspired my max TTL value for a DNS record. See RFC 2181


View Source
var ControllerExpiryCleanupInterval = 60 * time.Second // to be modified in unit tests


func StartMQTTManager

func StartMQTTManager(controller *Controller, mqttConf MQTTConf, scID string)


type API

type API struct {
	ID          string                 `json:"id"`
	Title       string                 `json:"title"`
	Description string                 `json:"description"`
	Protocol    string                 `json:"protocol"`
	URL         string                 `json:"url"`
	Spec        Spec                   `json:"spec"`
	Meta        map[string]interface{} `json:"meta"`

API - an API (e.g. REST API, MQTT API, etc.) exposed by the service

type BadRequestError

type BadRequestError struct{ Msg string }

Bad Request

func (*BadRequestError) Error

func (e *BadRequestError) Error() string

type Collection

type Collection struct {
	ID          string    `json:"id"`
	Description string    `json:"description"`
	Services    []Service `json:"services"`
	Page        int       `json:"page"`
	PerPage     int       `json:"per_page"`
	Total       int       `json:"total"`

Collection is the paginated list of services

type ConflictError

type ConflictError struct{ Msg string }

Conflict (non-unique id, assignment to read-only data)

func (*ConflictError) Error

func (e *ConflictError) Error() string

type Controller

type Controller struct {
	// contains filtered or unexported fields

func NewController

func NewController(storage Storage, listeners ...Listener) (*Controller, error)

func (*Controller) AddListener

func (c *Controller) AddListener(listener Listener)

func (*Controller) RemoveListener

func (c *Controller) RemoveListener(listener Listener)

func (*Controller) Stop

func (c *Controller) Stop() error

Stop the controller

type Error

type Error struct {
	// Code is the (http) code of the error
	Code int `json:"code"`
	// Message is the (human-readable) error message
	Message string `json:"message"`

Error describes an API error (serializable in JSON)

type HttpAPI

type HttpAPI struct {
	// contains filtered or unexported fields


func NewHTTPAPI(controller *Controller, id, description, version string) *HttpAPI


func (*HttpAPI) Delete

func (a *HttpAPI) Delete(w http.ResponseWriter, req *http.Request)

Deletes a service

func (*HttpAPI) ErrorResponse

func (a *HttpAPI) ErrorResponse(w http.ResponseWriter, code int, msgs ...string)

a.ErrorResponse writes error to HTTP ResponseWriter

func (*HttpAPI) Filter

func (a *HttpAPI) Filter(w http.ResponseWriter, req *http.Request)

Filters services

func (*HttpAPI) Get

func (a *HttpAPI) Get(w http.ResponseWriter, req *http.Request)

Retrieves a service

func (*HttpAPI) List

func (a *HttpAPI) List(w http.ResponseWriter, req *http.Request)

API Index: Lists services

func (*HttpAPI) Post

func (a *HttpAPI) Post(w http.ResponseWriter, req *http.Request)

Adds a service

func (*HttpAPI) Put

func (a *HttpAPI) Put(w http.ResponseWriter, req *http.Request)

Updates an existing service (Response: StatusOK) or creates a new one with the given id (Response: StatusCreated)

type LevelDBStorage

type LevelDBStorage struct {
	// contains filtered or unexported fields

LevelDB storage

func (*LevelDBStorage) Close

func (s *LevelDBStorage) Close() error

type Listener

type Listener interface {
	// contains filtered or unexported methods

Listener interface can be used for notification of the catalog updates NOTE: Implementations are expected to be thread safe

type MQTTClient

type MQTTClient struct {
	// contains filtered or unexported fields

type MQTTClientConf

type MQTTClientConf struct {
	Disabled   bool     `json:"disabled"`
	BrokerID   string   `json:"brokerID"`
	BrokerURI  string   `json:"brokerURI"`
	RegTopics  []string `json:"regTopics"`
	WillTopics []string `json:"willTopics"`
	QoS        byte     `json:"qos"`
	Username   string   `json:"username,omitempty"`
	Password   string   `json:"password,omitempty"`
	CaFile     string   `json:"caFile,omitempty"`   // trusted CA certificates file path
	CertFile   string   `json:"certFile,omitempty"` // client certificate file path
	KeyFile    string   `json:"keyFile,omitempty"`  // client private key file path

type MQTTConf

type MQTTConf struct {
	Client            MQTTClientConf   `json:"client"`
	AdditionalClients []MQTTClientConf `json:"additionalClients"`
	CommonRegTopics   []string         `json:"commonRegTopics"`
	CommonWillTopics  []string         `json:"commonWillTopics"`
	TopicPrefix       string           `json:"topicPrefix"`

func (MQTTConf) Validate

func (c MQTTConf) Validate() error

type MQTTManager

type MQTTManager struct {
	// contains filtered or unexported fields

type MemoryStorage

type MemoryStorage struct {
	// contains filtered or unexported fields

In-memory storage

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

func (*MemoryStorage) Close

func (ms *MemoryStorage) Close() error

type NotFoundError

type NotFoundError struct{ Msg string }

Not Found

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Service

type Service struct {
	ID          string                 `json:"id"`
	Description string                 `json:"description"`
	Title       string                 `json:"title"`
	Type        string                 `json:"type"`
	APIs        []API                  `json:"apis"`
	Meta        map[string]interface{} `json:"meta"`
	Doc         string                 `json:"doc"`
	TTL         uint32                 `json:"ttl"`
	CreatedAt   time.Time              `json:"createdAt"`
	UpdatedAt   time.Time              `json:"updatedAt"`
	ExpiresAt   time.Time              `json:"expiresAt"` // the time when service will be removed from the system (unless updated within TTL)

Service is a service entry in the catalog

type Spec

type Spec struct {
	MediaType string                 `json:"mediaType"`
	URL       string                 `json:"url"`
	Schema    map[string]interface{} `json:"schema"`

API.spec - the complete specification of the interface exposed by the service spec in the form of an url to external specification document is preferred, if not present, the 'schema' could be used Recommended - Request-response: OpenAPI/Swagger Spec, PubSub: AsyncAPI Spec

type Storage

type Storage interface {
	Close() error
	// contains filtered or unexported methods

Storage interface

func NewLevelDBStorage

func NewLevelDBStorage(dsn string, opts *opt.Options) (Storage, error)

Jump to

Keyboard shortcuts

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