Documentation ¶
Overview ¶
Package catalog contains the core functionalities of service catalog and exposes functions and structs for service representation, processing, and storage
Index ¶
- Constants
- Variables
- func StartMQTTManager(controller *Controller, mqttConf MQTTConf, scID string)
- type API
- type BadRequestError
- type Collection
- type ConflictError
- type Controller
- type Doc
- type Error
- type HttpAPI
- func (a *HttpAPI) Delete(w http.ResponseWriter, req *http.Request)
- func (a *HttpAPI) ErrorResponse(w http.ResponseWriter, code int, msgs ...string)
- func (a *HttpAPI) Filter(w http.ResponseWriter, req *http.Request)
- func (a *HttpAPI) Get(w http.ResponseWriter, req *http.Request)
- func (a *HttpAPI) List(w http.ResponseWriter, req *http.Request)
- func (a *HttpAPI) Post(w http.ResponseWriter, req *http.Request)
- func (a *HttpAPI) Put(w http.ResponseWriter, req *http.Request)
- type LevelDBStorage
- type Listener
- type MQTTClient
- type MQTTClientConf
- type MQTTConf
- type MQTTManager
- type MemoryStorage
- type NotFoundError
- type Service
- type Storage
Constants ¶
const ( DNSSDServiceType = "_linksmart-sc._tcp" MaxPerPage = 100 LoggerPrefix = "[sc] " CatalogBackendMemory = "memory" CatalogBackendLevelDB = "leveldb" APITypeHTTP = "HTTP" APITypeMQTT = "MQTT" MaxServiceTTL = 24 * 60 * 60 //in seconds )
Variables ¶
var ControllerExpiryCleanupInterval = 60 * time.Second // to be modified in unit tests
var SupportedBackends = map[string]bool{ CatalogBackendMemory: true, CatalogBackendLevelDB: true, }
Functions ¶
func StartMQTTManager ¶
func StartMQTTManager(controller *Controller, mqttConf MQTTConf, scID string)
Types ¶
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 ¶
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)
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
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"` }
type MQTTManager ¶
type MQTTManager struct {
// contains filtered or unexported fields
}
type MemoryStorage ¶
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