catalog

package
v2.3.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: Apache-2.0 Imports: 22 Imported by: 1

Documentation

Overview

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

Index

Constants

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

	CatalogBackendMemory  = "memory"
	CatalogBackendLevelDB = "leveldb"

	APITypeHTTP = "HTTP"
	APITypeMQTT = "MQTT"

	MaxServiceTTL = 24 * 60 * 60 //in seconds
)

Variables

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

Functions

func StartMQTTManager

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

Types

type API

type API struct {
	Protocol string `json:"protocol"`
	URL      string `json:"url"`
}

API is representation of service's API

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 {
	sync.RWMutex
	// 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 Doc

type Doc struct {
	Description string   `json:"description"`
	Type        string   `json:"type"`
	URL         string   `json:"url"`
	APIs        []string `json:"apis"`
}

Doc is an external resource documenting the service and/or APIs. E.g. OpenAPI specs, Wiki page

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

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

NewHTTPAPI creates a RESTful HTTP API

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 {
	MQTTClientConf
	// contains filtered or unexported fields
}

type MQTTClientConf

type MQTTClientConf struct {
	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 {
	sync.RWMutex
	// 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"`
	Name        string                 `json:"name"`
	APIs        map[string]string      `json:"apis"`
	Docs        []Doc                  `json:"docs"`
	Meta        map[string]interface{} `json:"meta"`
	TTL         uint                   `json:"ttl,omitempty"`
	Created     time.Time              `json:"created"`
	Updated     time.Time              `json:"updated"`
	// Expires is the time when service will be removed from the system (Only when TTL is set)
	Expires time.Time `json:"expires,omitempty"`
}

Service is a service entry in the catalog

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