api

package
v0.0.0-...-ad0604f Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HAFShowHidden = HttpAssetFlag(1 << iota)
	HAFDirListing
	HAFGZipContent
	HAFFlat
)
View Source
const (
	ErrorUnknownProtocol = ErrorCode(iota + 1)
	ErrorUnknownTransport
	ErrorInvalidProtocolTransport
	ErrorUnknownParameter
	ErrorInvalidParameterValue
	ErrorNoRequiredParameter
	ErrorNoDiscovery
	ErrorDiscoveryBusy
	ErrorNoDiscoveryID
	ErrorDiscoveryPending
	ErrorDiscoveryFailed
	ErrorServiceNoKey
	ErrorServiceNoID
	ErrorServiceExists
	ErrorServiceAliasExists
	ErrorServiceInitialize
	ErrorServiceKeyNotExists
	ErrorServiceAliasNotExists
	ErrorServiceStatusBad
	ErrorServiceBadPayload
	ErrorServiceSendBusy
	ErrorOtherError
)

Error codes

View Source
const (
	ParamTypeInt8   = "int8"
	ParamTypeInt16  = "int16"
	ParamTypeInt32  = "int32"
	ParamTypeInt64  = "int64"
	ParamTypeUint8  = "uint8"
	ParamTypeUint16 = "uint16"
	ParamTypeUint32 = "uint32"
	ParamTypeUint64 = "uint64"
	ParamTypeBool   = "bool"
	ParamTypeString = "string"
	ParamTypeEnum   = "enum"

	ParamTypeUint8Max = ^uint8(0)
	ParamTypeUint8Min = 0
	ParamTypeInt8Max  = int8(ParamTypeUint8Max >> 1)
	ParamTypeInt8Min  = -ParamTypeInt8Max - 1

	ParamTypeUint16Max = ^uint16(0)
	ParamTypeUint16Min = 0
	ParamTypeInt16Max  = int16(ParamTypeUint16Max >> 1)
	ParamTypeInt16Min  = -ParamTypeInt16Max - 1

	ParamTypeUint32Max = ^uint32(0)
	ParamTypeUint32Min = 0
	ParamTypeInt32Max  = int32(ParamTypeUint32Max >> 1)
	ParamTypeInt32Min  = -ParamTypeInt32Max - 1

	ParamTypeUint64Max = ^uint64(0)
	ParamTypeUint64Min = 0
	ParamTypeInt64Max  = int64(ParamTypeUint64Max >> 1)
	ParamTypeInt64Min  = -ParamTypeInt64Max - 1
)
View Source
const (
	Incoming = MessageState(iota)
	Outgoing
	OutgoingPending
	OutgoingFailed
	OutgoingRejected
	OutgoingTimedOut
)

Supported protocols identifiers

View Source
const (
	QueryUnexpected = QueryType(iota)
	QueryRestart
	QueryRestartResult
	QueryGetConfig
	QueryGetConfigResult
	QueryProtocolList
	QueryProtocolListResult
	QueryTransportList
	QueryTransportListResult
	QueryProtocolInfo
	QueryProtocolInfoResult
	QueryProtocolDiscover
	QueryProtocolDiscoverResult
	QueryProtocolDiscovery
	QueryProtocolDiscoveryResult
	QueryProtocolDiscoveryStarted
	QueryProtocolDiscoveryFinished
	QueryAddService
	QueryAddServiceResult
	QueryRemoveService
	QueryRemoveServiceResult
	QueryChangeServiceAlias
	QueryChangeServiceAliasResult
	QueryServiceStatus
	QueryServiceStatusResult
	QueryListServices
	QueryListServicesResult
	QuerySendToService
	QuerySendToServiceResult
	QueryGetMessage
	QueryGetMessageResult
	QueryListMessages
	QueryListMessagesResult
	QueryNewMessage
	QueryDropMessage
	QueryUpdateMessageState
	QueryEventSubscribe
	QueryEventSubscribeResult
)

All supported queries

View Source
const (
	EventDiscoveryStarted = SubscriptionEvent(iota)
	EventDiscoveryFinished
	EventNewMessage
	EventDropMessage
	EventUpdateMessageState
)

SubscriptionEvent types

View Source
const (
	MLFlagIgnoreReadError = MessageLogFlag(1 << iota)
)
View Source
const (
	ProtocolZWave = ProtocolIdentifier(iota + 1)
)

Supported protocols identifiers

View Source
const (
	TransportSerial = TransportIdentifier(iota + 1)
)

Supported transport identifiers

Variables

This section is empty.

Functions

func QueryTypeName

func QueryTypeName(t QueryType) string

Types

type ChangeServiceAlias

type ChangeServiceAlias struct {
	*ServiceID
	NewAlias string `json:"newAlias,omitempty"`
}

ChangeServiceAlias - change service alias request payload

type Config

type Config struct {
	WorkingDirectory string            `yaml:"workingDir,omitempty" json:"workingDir,omitempty"`
	Log              *LogConfig        `yaml:"log,omitempty" json:"log,omitempty"`
	HTTPServer       *HTTPServerConfig `yaml:"httpServer,omitempty" json:"httpServer,omitempty"`
	MessageLog       *MessageLogConfig `yaml:"messageLog,omitempty" json:"messageLog,omitempty"`
	Services         []ServiceConfig   `yaml:"services,omitempty" json:"services,omitempty"`
}

Config is a collection of top-level entries of configuration file

type DiscoveryEntry

type DiscoveryEntry struct {
	ServiceKey
	ParamValues `json:"params,omitempty"`
	Description string `json:"description,omitempty"`
}

DiscoveryEntry - information about service instance found during discovery

type DurationType

type DurationType time.Duration

func (DurationType) MarshalJSON

func (d DurationType) MarshalJSON() ([]byte, error)

func (DurationType) MarshalYAML

func (d DurationType) MarshalYAML() (interface{}, error)

func (DurationType) String

func (d DurationType) String() string

func (*DurationType) UnmarshalYAML

func (d *DurationType) UnmarshalYAML(node *yaml.Node) error

func (DurationType) Value

func (d DurationType) Value() time.Duration

type ErrorCode

type ErrorCode int

ErrorCode type

type ErrorInfo

type ErrorInfo struct {
	Code    ErrorCode     `json:"c"`
	Message string        `json:"m"`
	Params  []interface{} `json:"p,omitempty"`
	Err     error         `json:"-"`
}

ErrorInfo - error

func (*ErrorInfo) Error

func (e *ErrorInfo) Error() string

func (*ErrorInfo) Unwrap

func (e *ErrorInfo) Unwrap() error

type FileMode

type FileMode os.FileMode

func (FileMode) MarshalJSON

func (mode FileMode) MarshalJSON() ([]byte, error)

func (FileMode) MarshalYAML

func (mode FileMode) MarshalYAML() (interface{}, error)

func (FileMode) String

func (mode FileMode) String() string

func (*FileMode) UnmarshalYAML

func (mode *FileMode) UnmarshalYAML(node *yaml.Node) (err error)

func (FileMode) Value

func (mode FileMode) Value() os.FileMode

func (FileMode) WithDefault

func (mode FileMode) WithDefault(dv os.FileMode) os.FileMode

func (FileMode) WithDirDefault

func (mode FileMode) WithDirDefault() os.FileMode

func (FileMode) WithFileDefault

func (mode FileMode) WithFileDefault() os.FileMode

type HTTPAsset

type HTTPAsset struct {
	Route        string        `yaml:"route,omitempty" json:"route,omitempty"`
	Path         string        `yaml:"path,omitempty" json:"path,omitempty"`
	IndexFiles   []string      `yaml:"indexFiles,omitempty" json:"indexFiles,omitempty"`
	Includes     []string      `yaml:"includes,omitempty" json:"includes,omitempty"`
	Excludes     []string      `yaml:"excludes,omitempty" json:"excludes,omitempty"`
	GzipIncludes []string      `yaml:"gzipIncludes,omitempty" json:"gzipIncludes,omitempty"`
	GzipExcludes []string      `yaml:"gzipExcludes,omitempty" json:"gzipExcludes,omitempty"`
	Flags        HttpAssetFlag `yaml:"flags,omitempty" json:"flags,omitempty"`
}

type HTTPServerConfig

type HTTPServerConfig struct {
	Port              int          `yaml:"port,omitempty" json:"port,omitempty"`
	MaxConnections    uint         `yaml:"maxConnections,omitempty" json:"maxConnections,omitempty"`
	ReadTimeout       DurationType `yaml:"readTimeout,omitempty" json:"readTimeout,omitempty"`
	ReadHeaderTimeout DurationType `yaml:"readHeaderTimeout,omitempty" json:"readHeaderTimeout,omitempty"`
	WriteTimeout      DurationType `yaml:"writeTimeout,omitempty" json:"writeTimeout,omitempty"`
	IdleTimeout       DurationType `yaml:"idleTimeout,omitempty" json:"idleTimeout,omitempty"`
	MaxHeaderBytes    SizeType     `yaml:"maxHeaderBytes,omitempty" json:"maxHeaderBytes,omitempty"`
	Assets            []HTTPAsset  `yaml:"assets,omitempty" json:"assets,omitempty"`
}

HTTPServerConfig defines configuration entries for the HTTP server

type HttpAssetFlag

type HttpAssetFlag byte

func (HttpAssetFlag) MarshalJSON

func (flags HttpAssetFlag) MarshalJSON() ([]byte, error)

func (HttpAssetFlag) MarshalYAML

func (flags HttpAssetFlag) MarshalYAML() (interface{}, error)

func (HttpAssetFlag) String

func (flags HttpAssetFlag) String() string

func (*HttpAssetFlag) UnmarshalJSON

func (flags *HttpAssetFlag) UnmarshalJSON(data []byte) (err error)

func (*HttpAssetFlag) UnmarshalYAML

func (flags *HttpAssetFlag) UnmarshalYAML(node *yaml.Node) (err error)

type ListMessage

type ListMessage struct {
	ServiceIndex int `json:"serviceIndex"`
	*Message
}

ListMessage contains message info for the list messages response

type ListMessages

type ListMessages struct {
	FromIndex        *int             `json:"fromIndex,omitempty"`
	FromID           *uuid.UUID       `json:"fromId,omitempty"`
	FromTime         *time.Time       `json:"fromTime,omitempty"`
	FromExclusive    bool             `json:"fromExclusive,omitempty"`
	UntilIndex       *int             `json:"untilIndex,omitempty"`
	UntilID          *uuid.UUID       `json:"untilId,omitempty"`
	UntilTime        *time.Time       `json:"untilTime,omitempty"`
	UntilExclusive   bool             `json:"untilExclusive,omitempty"`
	Count            int              `json:"count"`
	CountAfterFilter bool             `json:"countAfterFilter,omitempty"`
	Services         []*ServiceID     `json:"services,omitempty"`
	States           []MessageState   `json:"states,omitempty"`
	Payloads         [][]PayloadMatch `json:"payloads,omitempty"`
}

ListMessages defines list messages request payload

type ListMessagesResult

type ListMessagesResult struct {
	Services []*ServiceID   `json:"services,omitempty"`
	Messages []*ListMessage `json:"messages,omitempty"`
	Count    int            `json:"count"`
}

ListMessagesResult defines list messages result payload

type ListServices

type ListServices struct {
	Protocols  []ProtocolIdentifier  `json:"protocols,omitempty"`
	Transports []TransportIdentifier `json:"transports,omitempty"`
	Entries    []string              `json:"entries,omitempty"`
	Aliases    []string              `json:"aliases,omitempty"`
}

ListServices - get list of services request payload

type ListServicesEntry

type ListServicesEntry struct {
	*ServiceEntry
	*StatusReply
}

ListServicesEntry - service information for services list result

type ListServicesResult

type ListServicesResult struct {
	Services []ListServicesEntry `json:"services,omitempty"`
}

ListServicesResult - get list of services query result

type LogConfig

type LogConfig struct {
	Dir        string       `yaml:"dir,omitempty" json:"dir,omitempty"`
	File       string       `yaml:"file,omitempty" json:"file,omitempty"`
	DirMode    FileMode     `yaml:"dirMode,omitempty" json:"dirMode,omitempty"`
	FileMode   FileMode     `yaml:"fileMode,omitempty" json:"fileMode,omitempty"`
	MaxSize    SizeType     `yaml:"maxSize,omitempty" json:"maxSize,omitempty"`
	MaxAge     DurationType `yaml:"maxAge,omitempty" json:"maxAge,omitempty"` // seconds
	Backups    uint32       `yaml:"backups,omitempty" json:"backups,omitempty"`
	BackupDays uint32       `yaml:"backupDays,omitempty" json:"backupDays,omitempty"`
	Archive    string       `yaml:"archive,omitempty" json:"archive,omitempty"`
}

LogConfig defines configuration entries for the serivce logging

type Message

type Message struct {
	Time    time.Time    `json:"time"`
	ID      uuid.UUID    `json:"id"`
	State   MessageState `json:"state"`
	Payload []byte       `json:"payload"`
}

Message struct represent the message sent to the service

type MessageEntry

type MessageEntry struct {
	*ServiceKey
	*Message
}

MessageEntry defines message and corresponding service pair

type MessageLogConfig

type MessageLogConfig struct {
	// maximal messages log size, in bytes. must be greater or equal to 8192. Default value is 10MB
	MaxSize SizeType `yaml:"maxSize,omitempty" json:"maxSize,omitempty"`
	// file where messages log will be stored. If not specified or empty the message log will not persist
	File       string         `yaml:"file,omitempty" json:"file,omitempty"`
	DirMode    FileMode       `yaml:"dirMode,omitempty" json:"dirMode,omitempty"`
	FileMode   FileMode       `yaml:"fileMode,omitempty" json:"fileMode,omitempty"`
	Flags      MessageLogFlag `yaml:"flags,omitempty" json:"flags,omitempty"`
	AutoPesist DurationType   `yaml:"autoPersist,omitempty" json:"autoPersist,omitempty"`
}

MessageLogConfig defines message log configuration entries

type MessageLogFlag

type MessageLogFlag byte

func (MessageLogFlag) MarshalJSON

func (flags MessageLogFlag) MarshalJSON() ([]byte, error)

func (MessageLogFlag) MarshalYAML

func (flags MessageLogFlag) MarshalYAML() (interface{}, error)

func (MessageLogFlag) String

func (flags MessageLogFlag) String() string

func (*MessageLogFlag) UnmarshalJSON

func (flags *MessageLogFlag) UnmarshalJSON(data []byte) (err error)

func (*MessageLogFlag) UnmarshalYAML

func (flags *MessageLogFlag) UnmarshalYAML(node *yaml.Node) (err error)

type MessageState

type MessageState uint8

MessageState type

type ParamInfoEntry

type ParamInfoEntry struct {
	Description  string   `json:"description"`
	Type         string   `json:"type"`
	DefaultValue string   `json:"defaultValue,omitempty"`
	EnumValues   []string `json:"enumValues,omitempty"`
}

ParamInfoEntry - information about named parameter

type ParamValues

type ParamValues map[string]interface{}

ParamValues type defines named parameter values

func (ParamValues) Copy

func (pv ParamValues) Copy() ParamValues

Copy creates copy of parameter-values

func (ParamValues) Raw

func (pv ParamValues) Raw() (r RawParamValues)

Raw converts parameter-values into their raw form (string-string)

type PayloadMatch

type PayloadMatch struct {
	Content []byte `json:"content,omitempty"`
	At      *int   `json:"at,omitempty"`
}

PayloadMatch defines byte sequence to match with payload At == nil - payload must contain the content At >= 0 - payload must include the content at provided position "At" At < 0 - payload must include the content at provided position "len(payload) - len(content) + At + 1"

type ProtocolDiscover

type ProtocolDiscover struct {
	Protocol  ProtocolIdentifier  `json:"protocol"`
	Transport TransportIdentifier `json:"transport"`
	Params    RawParamValues      `json:"params,omitempty"`
}

ProtocolDiscover - discover query request payload

type ProtocolDiscoverResult

type ProtocolDiscoverResult struct {
	ID    *uuid.UUID `json:"id,omitempty"`
	Error *ErrorInfo `json:"error,omitempty"`
}

ProtocolDiscoverResult - discover query response payload

type ProtocolDiscovery

type ProtocolDiscovery struct {
	ID   uuid.UUID `json:"id"`
	Stop bool      `json:"stop"`
}

ProtocolDiscovery defines protocol discovery query payload

type ProtocolDiscoveryResult

type ProtocolDiscoveryResult struct {
	ID      uuid.UUID         `json:"id"`
	Entries []*DiscoveryEntry `json:"entries"`
	Error   *ErrorInfo        `json:"error,omitempty"`
}

ProtocolDiscoveryResult defines discovery query response payload

type ProtocolDiscoveryStarted

type ProtocolDiscoveryStarted struct {
	ProtocolDiscover
	ID uuid.UUID `json:"id"`
}

DiscoveryRequest contains information about started discovery query

type ProtocolIdentifier

type ProtocolIdentifier uint8

ProtocolIdentifier type

func (ProtocolIdentifier) IsValid

func (protocol ProtocolIdentifier) IsValid() bool

IsValid verifies if protocol identifer is valid

type ProtocolInfo

type ProtocolInfo struct {
	Protocols  []ProtocolIdentifier  `json:"protocols,omitempty"`
	Transports []TransportIdentifier `json:"transports,omitempty"`
}

ProtocolInfo - get protocol(s) detailed information

type ProtocolInfoEntry

type ProtocolInfoEntry struct {
	ID         ProtocolIdentifier            `json:"id"`
	Valid      bool                          `json:"valid"`
	Name       string                        `json:"name,omitempty"`
	Transports []*ProtocolTransportInfoEntry `json:"transports,omitempty"`
}

ProtocolInfoEntry - protocol detaild information

type ProtocolInfoResult

type ProtocolInfoResult struct {
	Protocols []*ProtocolInfoEntry
}

ProtocolInfoResult - the response to get list of all available transports despite the protocol

type ProtocolListEntry

type ProtocolListEntry struct {
	ID   ProtocolIdentifier `json:"id"`
	Name string             `json:"name"`
}

ProtocolListEntry - list of supported protocols

type ProtocolListResult

type ProtocolListResult struct {
	Protocols []*ProtocolListEntry
}

ProtocolListResult - get list of supported protocols response

type ProtocolTransportInfoEntry

type ProtocolTransportInfoEntry struct {
	ID              TransportIdentifier        `json:"id"`
	Valid           bool                       `json:"valid"`
	Name            string                     `json:"name,omitempty"`
	Params          map[string]*ParamInfoEntry `json:"params,omitempty"`
	Discoverable    bool                       `json:"discoverable,omitempty"`
	DiscoveryParams map[string]*ParamInfoEntry `json:"discoveryParams,omitempty"`
}

ProtocolTransportInfoEntry - protocol detaild information

type Query

type Query struct {
	Type    QueryType
	ID      string
	Payload interface{}
}

Query struct

func (*Query) MarshalJSON

func (c *Query) MarshalJSON() ([]byte, error)

MarshalJSON func

func (*Query) UnmarshalJSON

func (c *Query) UnmarshalJSON(data []byte) error

UnmarshalJSON func

type QueryType

type QueryType uint16

QueryType type

type RawParamValues

type RawParamValues map[string]string

RawParamValues defines raw parameter values - before parsing

type SendToService

type SendToService struct {
	*ServiceID
	Payload []byte `json:"payload,omitempty"`
}

SendToService - send message to service request payload

type SendToServiceResult

type SendToServiceResult struct {
	*StatusReply
	*Message
}

SendToServiceResult - send message to service result payload

type ServiceConfig

type ServiceConfig struct {
	Alias     string            `yaml:"alias,omitempty" json:"alias,omitempty"`
	Protocol  string            `yaml:"protocol" json:"protocol"`
	Transport string            `yaml:"transport" json:"transport"`
	Entry     string            `yaml:"entry,omitempty" json:"entry,omitempty"`
	Params    map[string]string `yaml:"params,omitempty" json:"params,omitempty"`
}

ServiceConfig defines configuration of active services

type ServiceEntry

type ServiceEntry struct {
	*ServiceKey
	Params RawParamValues `json:"params,omitempty"`
	Alias  string         `json:"alias,omitempty"`
}

ServiceEntry declares service identification and configuration

type ServiceID

type ServiceID struct {
	*ServiceKey
	Alias string `json:"alias,omitempty"`
}

ServiceID defines service identification in API

type ServiceKey

type ServiceKey struct {
	Protocol  ProtocolIdentifier  `json:"protocol"`
	Transport TransportIdentifier `json:"transport"`
	Entry     string              `json:"entry"`
}

ServiceKey defines service unique identifier/key

type SizeType

type SizeType int64

func (SizeType) MarshalJSON

func (sz SizeType) MarshalJSON() ([]byte, error)

func (SizeType) MarshalYAML

func (sz SizeType) MarshalYAML() (interface{}, error)

func (SizeType) String

func (sz SizeType) String() string

func (*SizeType) UnmarshalYAML

func (sz *SizeType) UnmarshalYAML(node *yaml.Node) error

func (SizeType) Value

func (sz SizeType) Value() int64

type StatusReply

type StatusReply struct {
	Error   *ErrorInfo `json:"error,omitempty"`
	Success bool       `json:"success,omitempty"`
}

StatusReply - common operation status reply (success/error)

type Subscription

type Subscription struct {
	Subscribe bool                `json:"subscribe"`
	AllEvents bool                `json:"all,omitempty"`
	Events    []SubscriptionEvent `json:"events,omitempty"`
}

Subscription query structure

type SubscriptionEvent

type SubscriptionEvent byte

SubscriptionEvent defines types of events to subscribe (web sockets only)

func (SubscriptionEvent) MarshalJSON

func (c SubscriptionEvent) MarshalJSON() ([]byte, error)

MarshalJSON func for SubscriptionEvent value

func (SubscriptionEvent) String

func (c SubscriptionEvent) String() string

func (*SubscriptionEvent) UnmarshalJSON

func (event *SubscriptionEvent) UnmarshalJSON(data []byte) error

UnmarshalJSON func for SubscriptionEvent value

type TransportIdentifier

type TransportIdentifier uint8

TransportIdentifier type

func (TransportIdentifier) IsValid

func (transport TransportIdentifier) IsValid() bool

IsValid verifies if protocol identifer is valid

type TransportListEntry

type TransportListEntry struct {
	ID   TransportIdentifier `json:"id"`
	Name string              `json:"name"`
}

TransportListEntry - list of all available transports despite the protocol

type TransportListResult

type TransportListResult struct {
	Transports []*TransportListEntry
}

TransportListResult - the response to get list of all available transports despite the protocol

type UpdateMessageState

type UpdateMessageState struct {
	*MessageEntry
	PrevState MessageState
}

UpdateMessageState defines payload of UpdateMessageState notification

Jump to

Keyboard shortcuts

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