Documentation ¶
Index ¶
- Constants
- func ErrorMsg(res *http.Response) string
- func ErrorResponse(w http.ResponseWriter, code int, msgs ...string)
- func GetPageOfSlice(slice []string, page, perPage, maxPerPage int) ([]string, error)
- func GetPagingAttr(total, page, perPage, maxPerPage int) (int, int, error)
- func HTTPDoAuth(req *http.Request, ticket *obtainer.Client) (*http.Response, error)
- func HTTPRequest(method string, url string, headers map[string][]string, body io.Reader, ...) (*http.Response, error)
- func MatchObject(object interface{}, path []string, op string, value string) (bool, error)
- func NewStaticHandler(staticDir string) http.HandlerFunc
- func ParsePagingParams(page, perPage string, maxPerPage int) (int, int, error)
- func RegisterDevice(client CatalogClient, d *Device) error
- func RegisterDeviceWithKeepalive(endpoint string, discover bool, d Device, sigCh <-chan bool, ...)
- func ValidatePagingParams(page, perPage, maxPerPage int) error
- type BadRequestError
- type CatalogClient
- type CatalogController
- type CatalogStorage
- type ConflictError
- type Controller
- type Device
- type DeviceCollection
- type Devices
- type Error
- type JSONLDResource
- type JSONLDSimpleDevice
- type LevelDBStorage
- type LocalCatalogClient
- func (self *LocalCatalogClient) Add(r *Device) (string, error)
- func (self *LocalCatalogClient) Delete(id string) error
- func (self *LocalCatalogClient) Filter(path, op, value string, page, perPage int) ([]SimpleDevice, int, error)
- func (self *LocalCatalogClient) FilterResources(path, op, value string, page, perPage int) ([]Resource, int, error)
- func (self *LocalCatalogClient) Get(id string) (*SimpleDevice, error)
- func (self *LocalCatalogClient) GetResource(id string) (*Resource, error)
- func (self *LocalCatalogClient) List(page int, perPage int) ([]SimpleDevice, int, error)
- func (self *LocalCatalogClient) ListResources(page int, perPage int) ([]Resource, int, error)
- func (self *LocalCatalogClient) Update(id string, r *Device) error
- type Map
- type MemoryStorage
- type NotFoundError
- type Protocol
- type ReadableCatalogAPI
- func (a *ReadableCatalogAPI) Filter(w http.ResponseWriter, req *http.Request)
- func (a *ReadableCatalogAPI) FilterResources(w http.ResponseWriter, req *http.Request)
- func (a *ReadableCatalogAPI) Get(w http.ResponseWriter, req *http.Request)
- func (a *ReadableCatalogAPI) GetResource(w http.ResponseWriter, req *http.Request)
- func (a *ReadableCatalogAPI) Index(w http.ResponseWriter, req *http.Request)
- func (a *ReadableCatalogAPI) List(w http.ResponseWriter, req *http.Request)
- func (a *ReadableCatalogAPI) ListResources(w http.ResponseWriter, req *http.Request)
- type RemoteCatalogClient
- func (c *RemoteCatalogClient) Add(d *Device) (string, error)
- func (c *RemoteCatalogClient) Delete(id string) error
- func (c *RemoteCatalogClient) Filter(path, op, value string, page, perPage int) ([]SimpleDevice, int, error)
- func (c *RemoteCatalogClient) FilterResources(path, op, value string, page, perPage int) ([]Resource, int, error)
- func (c *RemoteCatalogClient) Get(id string) (*SimpleDevice, error)
- func (c *RemoteCatalogClient) GetResource(id string) (*Resource, error)
- func (c *RemoteCatalogClient) List(page int, perPage int) ([]SimpleDevice, int, error)
- func (c *RemoteCatalogClient) ListResources(page int, perPage int) ([]Resource, int, error)
- func (c *RemoteCatalogClient) Update(id string, d *Device) error
- type Resource
- type ResourceCollection
- type Resources
- type SimpleDevice
- type WritableCatalogAPI
Constants ¶
const ( TypeDevices = "devices" TypeResources = "resources" CtxPath = "/ctx/rc.jsonld" )
const ( DNSSDServiceType = "_linksmart-rc._tcp" MaxPerPage = 100 ApiVersion = "1.0.0" ApiName = "ResourceCatalog" ApiDeviceCollectionType = "Devices" ApiResourceCollectionType = "Resources" ApiDeviceType = "Device" ApiResourceType = "Resource" CatalogBackendMemory = "memory" CatalogBackendLevelDB = "leveldb" StaticLocation = "/static" )
const ( GetParamPage = "page" GetParamPerPage = "per_page" )
const ( FOpEquals = "equals" FOpPrefix = "prefix" FOpSuffix = "suffix" FOpContains = "contains" )
Variables ¶
This section is empty.
Functions ¶
func ErrorResponse ¶
func ErrorResponse(w http.ResponseWriter, code int, msgs ...string)
ErrorResponse writes error to HTTP ResponseWriter
func GetPageOfSlice ¶
Returns a 'slice' of the given slice based on the requested 'page'
func GetPagingAttr ¶
Returns offset and limit representing a subset of the given slice total size
based on the requested 'page'
func HTTPDoAuth ¶
Send an HTTP request with Authorization entity-header.
Ticket is renewed once in case of failure.
func HTTPRequest ¶
func HTTPRequest(method string, url string, headers map[string][]string, body io.Reader, ticket *obtainer.Client) (*http.Response, error)
Constructs and submits an HTTP request and returns the response
func MatchObject ¶
func NewStaticHandler ¶
func NewStaticHandler(staticDir string) http.HandlerFunc
Serves static and all /static/ctx files as ld+json
func ParsePagingParams ¶
Parses string paging parameters to integers
func RegisterDevice ¶
func RegisterDevice(client CatalogClient, d *Device) error
Registers device given a configured Catalog Client
func RegisterDeviceWithKeepalive ¶
func RegisterDeviceWithKeepalive(endpoint string, discover bool, d Device, sigCh <-chan bool, wg *sync.WaitGroup, ticket *obtainer.Client)
Registers device in the remote catalog endpoint: catalog endpoint. If empty - will be discovered using DNS-SD d: device registration sigCh: channel for shutdown signalisation from upstream
func ValidatePagingParams ¶
Validates paging parameters
Types ¶
type BadRequestError ¶
type BadRequestError struct {
// contains filtered or unexported fields
}
Bad Request
func (*BadRequestError) Error ¶
func (e *BadRequestError) Error() string
type CatalogClient ¶
type CatalogClient interface { // CRUD Get(id string) (*SimpleDevice, error) Add(d *Device) (string, error) Update(id string, d *Device) error Delete(id string) error // Returns a slice of Devices given: // page - page in the collection // perPage - number of entries per page List(page, perPage int) ([]SimpleDevice, int, error) // Returns a slice of Devices given: path, operation, value, page, perPage Filter(path, op, value string, page, perPage int) ([]SimpleDevice, int, error) // Returns a single resource GetResource(id string) (*Resource, error) // Returns a slice of Resources given: // page - page in the collection // perPage - number of entries per page ListResources(page, perPage int) ([]Resource, int, error) // Returns a slice of Resources given: path, operation, value, page, perPage FilterResources(path, op, value string, page, perPage int) ([]Resource, int, error) }
Catalog client
func NewLocalCatalogClient ¶
func NewLocalCatalogClient(controller CatalogController) CatalogClient
func NewRemoteCatalogClient ¶
func NewRemoteCatalogClient(serverEndpoint string, ticket *obtainer.Client) (CatalogClient, error)
type CatalogController ¶
type CatalogController interface { Stop() error // contains filtered or unexported methods }
Controller interface
func NewController ¶
func NewController(storage CatalogStorage, apiLocation string) (CatalogController, error)
type CatalogStorage ¶
type CatalogStorage interface { Close() error // contains filtered or unexported methods }
Storage interface
func NewLevelDBStorage ¶
func NewLevelDBStorage(dsn string, opts *opt.Options) (CatalogStorage, error)
type ConflictError ¶
type ConflictError struct {
// contains filtered or unexported fields
}
Conflict (non-unique id, assignment to read-only data)
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
type Controller ¶
type Device ¶
type Device struct { Id string `json:"id"` URL string `json:"url"` Type string `json:"type"` Name string `json:"name,omitempty"` Meta map[string]interface{} `json:"meta,omitempty"` Description string `json:"description,omitempty"` Ttl uint `json:"ttl,omitempty"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` Expires *time.Time `json:"expires,omitempty"` Resources Resources `json:"resources"` }
Device
type DeviceCollection ¶
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 JSONLDResource ¶
type JSONLDSimpleDevice ¶
type JSONLDSimpleDevice struct { Context string `json:"@context"` *SimpleDevice }
type LevelDBStorage ¶
type LevelDBStorage struct {
// contains filtered or unexported fields
}
LevelDB storage
func (*LevelDBStorage) Close ¶
func (s *LevelDBStorage) Close() error
type LocalCatalogClient ¶
type LocalCatalogClient struct {
// contains filtered or unexported fields
}
func (*LocalCatalogClient) Add ¶
func (self *LocalCatalogClient) Add(r *Device) (string, error)
Adds a device and returns its id
func (*LocalCatalogClient) Delete ¶
func (self *LocalCatalogClient) Delete(id string) error
func (*LocalCatalogClient) Filter ¶
func (self *LocalCatalogClient) Filter(path, op, value string, page, perPage int) ([]SimpleDevice, int, error)
func (*LocalCatalogClient) FilterResources ¶
func (*LocalCatalogClient) Get ¶
func (self *LocalCatalogClient) Get(id string) (*SimpleDevice, error)
func (*LocalCatalogClient) GetResource ¶
func (self *LocalCatalogClient) GetResource(id string) (*Resource, error)
func (*LocalCatalogClient) List ¶
func (self *LocalCatalogClient) List(page int, perPage int) ([]SimpleDevice, int, error)
func (*LocalCatalogClient) ListResources ¶
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
AVL Tree: sorted nodes according to keys
A node of the AVL Tree (go-avltree)
type MemoryStorage ¶
In-memory storage
func NewMemoryStorage ¶
func NewMemoryStorage() *MemoryStorage
func (*MemoryStorage) Close ¶
func (s *MemoryStorage) Close() error
type NotFoundError ¶
type NotFoundError struct {
// contains filtered or unexported fields
}
Not Found
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type Protocol ¶
type Protocol struct { Type string `json:"type"` Endpoint map[string]interface{} `json:"endpoint"` Methods []string `json:"methods,omitempty"` ContentTypes []string `json:"content-types,omitempty"` }
Protocol describes the resource API
type ReadableCatalogAPI ¶
type ReadableCatalogAPI struct {
// contains filtered or unexported fields
}
Read-only catalog api
func NewReadableCatalogAPI ¶
func NewReadableCatalogAPI(controller CatalogController, apiLocation, staticLocation, description string) *ReadableCatalogAPI
func (*ReadableCatalogAPI) Filter ¶
func (a *ReadableCatalogAPI) Filter(w http.ResponseWriter, req *http.Request)
Lists filtered devices in a DeviceCollection
func (*ReadableCatalogAPI) FilterResources ¶
func (a *ReadableCatalogAPI) FilterResources(w http.ResponseWriter, req *http.Request)
Lists filtered resources in a ResourceCollection
func (*ReadableCatalogAPI) Get ¶
func (a *ReadableCatalogAPI) Get(w http.ResponseWriter, req *http.Request)
Gets a single Device
func (*ReadableCatalogAPI) GetResource ¶
func (a *ReadableCatalogAPI) GetResource(w http.ResponseWriter, req *http.Request)
Gets a single Resource
func (*ReadableCatalogAPI) Index ¶
func (a *ReadableCatalogAPI) Index(w http.ResponseWriter, req *http.Request)
Index of API
func (*ReadableCatalogAPI) List ¶
func (a *ReadableCatalogAPI) List(w http.ResponseWriter, req *http.Request)
Lists devices in a DeviceCollection
func (*ReadableCatalogAPI) ListResources ¶
func (a *ReadableCatalogAPI) ListResources(w http.ResponseWriter, req *http.Request)
Lists resources in a ResourceCollection
type RemoteCatalogClient ¶
type RemoteCatalogClient struct {
// contains filtered or unexported fields
}
func (*RemoteCatalogClient) Add ¶
func (c *RemoteCatalogClient) Add(d *Device) (string, error)
Adds a device and returns its id
func (*RemoteCatalogClient) Delete ¶
func (c *RemoteCatalogClient) Delete(id string) error
Deletes a device
func (*RemoteCatalogClient) Filter ¶
func (c *RemoteCatalogClient) Filter(path, op, value string, page, perPage int) ([]SimpleDevice, int, error)
Filters devices
func (*RemoteCatalogClient) FilterResources ¶
func (c *RemoteCatalogClient) FilterResources(path, op, value string, page, perPage int) ([]Resource, int, error)
Filter resources
func (*RemoteCatalogClient) Get ¶
func (c *RemoteCatalogClient) Get(id string) (*SimpleDevice, error)
Retrieves a device
func (*RemoteCatalogClient) GetResource ¶
func (c *RemoteCatalogClient) GetResource(id string) (*Resource, error)
Retrieves a resource
func (*RemoteCatalogClient) List ¶
func (c *RemoteCatalogClient) List(page int, perPage int) ([]SimpleDevice, int, error)
Retrieves a page from the device collection
func (*RemoteCatalogClient) ListResources ¶
Retrieves a page from the resource collection
type Resource ¶
type Resource struct { Id string `json:"id"` URL string `json:"url"` Type string `json:"type"` Name string `json:"name,omitempty"` Meta map[string]interface{} `json:"meta,omitempty"` Protocols []Protocol `json:"protocols"` Representation map[string]interface{} `json:"representation,omitempty"` Device string `json:"device"` // URL of device }
Resource
type ResourceCollection ¶
type SimpleDevice ¶
Device with only IDs of resources
type WritableCatalogAPI ¶
type WritableCatalogAPI struct {
*ReadableCatalogAPI
}
Writable catalog api
func NewWritableCatalogAPI ¶
func NewWritableCatalogAPI(controller CatalogController, apiLocation, staticLocation, description string) *WritableCatalogAPI
func (*WritableCatalogAPI) Delete ¶
func (a *WritableCatalogAPI) Delete(w http.ResponseWriter, req *http.Request)
Deletes a device
func (*WritableCatalogAPI) Post ¶
func (a *WritableCatalogAPI) Post(w http.ResponseWriter, req *http.Request)
Adds a Device
func (*WritableCatalogAPI) Put ¶
func (a *WritableCatalogAPI) Put(w http.ResponseWriter, req *http.Request)
Updates an existing device (Response: StatusOK) If the device does not exist, a new one will be created with the given id (Response: StatusCreated)