Documentation
¶
Index ¶
- Constants
- Variables
- func AddResponseChannel(c CoapServer, msgId uint16, ch chan *CoapResponseChannel)
- func COAPProxyHandler(c CoapServer, msg Message, session Session)
- func CoapCodeToString(code CoapCode) string
- func DeleteResponseChannel(c CoapServer, msgId uint16)
- func GenerateMessageID() uint16
- func GenerateToken(l int) string
- func GetResponseChannel(c CoapServer, msgId uint16) (ch chan *CoapResponseChannel)
- func HTTPCOAPProxyHandler(msg *Message, conn *net.UDPConn, addr net.Addr)
- func HTTPProxyHandler(c CoapServer, msg Message, session Session)
- func IsCoapURI(uri string) bool
- func IsCriticalOption(opt Option) bool
- func IsElectiveOption(opt Option) bool
- func IsHTTPURI(uri string) bool
- func IsProxyRequest(msg Message) bool
- func IsRepeatableOption(opt Option) bool
- func IsValidOption(opt Option) bool
- func MessageSizeAllowed(req Request) bool
- func MessageToBytes(msg Message) ([]byte, error)
- func MethodString(c CoapCode) string
- func NewResponseChannel() (ch chan *CoapResponseChannel)
- func NullProxyFilter(Message, net.Addr) bool
- func NullProxyHandler(c CoapServer, msg Message, session Session)
- func OptionNumberToString(o OptionCode) string
- func PayloadAsString(p MessagePayload) string
- func PrintMessage(msg Message)
- func PrintOptions(msg Message)
- func ValidCoapMediaTypeCode(mt MediaType) bool
- func ValidateMessage(msg Message) error
- type Block1Option
- type BlockMessage
- type BlockSizeType
- type BySequence
- type BytesPayload
- type CoapBlockMessage
- type CoapCode
- type CoapMessage
- func (m *CoapMessage) AddOption(code OptionCode, value interface{})
- func (m *CoapMessage) AddOptions(opts []Option)
- func (m *CoapMessage) CloneOptions(cm Message, opts ...OptionCode)
- func (m *CoapMessage) GetAcceptedContent() MediaType
- func (m *CoapMessage) GetAllOptions() []Option
- func (m *CoapMessage) GetCode() CoapCode
- func (m *CoapMessage) GetCodeString() string
- func (m *CoapMessage) GetLocationPath() string
- func (m *CoapMessage) GetMessageId() uint16
- func (m *CoapMessage) GetMessageType() uint8
- func (m *CoapMessage) GetMethod() uint8
- func (m CoapMessage) GetOption(id OptionCode) Option
- func (m CoapMessage) GetOptions(id OptionCode) []Option
- func (m CoapMessage) GetOptionsAsString(id OptionCode) []string
- func (m *CoapMessage) GetPayload() MessagePayload
- func (m *CoapMessage) GetToken() []byte
- func (m *CoapMessage) GetTokenLength() uint8
- func (m *CoapMessage) GetTokenString() string
- func (m CoapMessage) GetURIPath() string
- func (m *CoapMessage) RemoveOptions(id OptionCode)
- func (m *CoapMessage) ReplaceOptions(code OptionCode, opts []Option)
- func (c *CoapMessage) SetBlock1Option(opt Option)
- func (m *CoapMessage) SetMessageId(id uint16)
- func (m *CoapMessage) SetMessageType(t uint8)
- func (m *CoapMessage) SetPayload(p MessagePayload)
- func (m *CoapMessage) SetStringPayload(s string)
- func (m *CoapMessage) SetToken(t []byte)
- type CoapObserveMessage
- type CoapOption
- type CoapRequest
- func (c *CoapRequest) GetAttribute(o string) string
- func (c *CoapRequest) GetAttributeAsInt(o string) int
- func (c *CoapRequest) GetAttributes() map[string]string
- func (c *CoapRequest) GetMessage() Message
- func (c *CoapRequest) GetSession() Session
- func (c *CoapRequest) GetURIQuery(q string) string
- func (c *CoapRequest) SetConfirmable(con bool)
- func (c *CoapRequest) SetMediaType(mt MediaType)
- func (c *CoapRequest) SetPayload(b []byte)
- func (c *CoapRequest) SetProxyURI(uri string)
- func (c *CoapRequest) SetRequestURI(uri string)
- func (c *CoapRequest) SetStringPayload(s string)
- func (c *CoapRequest) SetToken(t string)
- func (c *CoapRequest) SetURIQuery(k string, v string)
- type CoapResponseChannel
- type CoapServer
- type Connection
- type CoreAttribute
- type CoreAttributes
- type CoreLinkFormatPayload
- type CoreResource
- type DTLSConnection
- func (c *DTLSConnection) CancelObserveResource(resource string, token string) (err error)
- func (c *DTLSConnection) Close() error
- func (c *DTLSConnection) Observe(ch chan ObserveMessage)
- func (c *DTLSConnection) ObserveResource(resource string) (tok string, err error)
- func (c *DTLSConnection) Read(b []byte) (int, error)
- func (c *DTLSConnection) Send(req Request) (resp Response, err error)
- func (c *DTLSConnection) StopObserve(ch chan ObserveMessage)
- func (c *DTLSConnection) Write(b []byte) (int, error)
- type DTLSServerSession
- type DefaultCoapServer
- func (s *DefaultCoapServer) AddObservation(resource, token string, session Session)
- func (s *DefaultCoapServer) AllowProxyForwarding(msg Message, addr net.Addr) bool
- func (s *DefaultCoapServer) Delete(path string, fn RouteHandler) Route
- func (s *DefaultCoapServer) DeleteSession(ssn Session)
- func (s *DefaultCoapServer) ForwardCoap(msg Message, session Session)
- func (s *DefaultCoapServer) ForwardHTTP(msg Message, session Session)
- func (s *DefaultCoapServer) Get(path string, fn RouteHandler) Route
- func (s *DefaultCoapServer) GetCookieSecret() []byte
- func (s *DefaultCoapServer) GetEvents() Events
- func (s *DefaultCoapServer) GetRoutes() []Route
- func (s *DefaultCoapServer) GetSession(addr string) Session
- func (s *DefaultCoapServer) HandlePSK(fn func(id string) []byte)
- func (s *DefaultCoapServer) HasObservation(resource string, addr net.Addr) bool
- func (s *DefaultCoapServer) ListenAndServe(addr string)
- func (s *DefaultCoapServer) ListenAndServeDTLS(addr string)
- func (s *DefaultCoapServer) NewRoute(path string, method CoapCode, fn RouteHandler) Route
- func (s *DefaultCoapServer) NotifyChange(resource, value string, confirm bool)
- func (s *DefaultCoapServer) OnBlockMessage(fn FnEventBlockMessage)
- func (s *DefaultCoapServer) OnClose(fn FnEventClose)
- func (s *DefaultCoapServer) OnDiscover(fn FnEventDiscover)
- func (s *DefaultCoapServer) OnError(fn FnEventError)
- func (s *DefaultCoapServer) OnMessage(fn FnEventMessage)
- func (s *DefaultCoapServer) OnNotify(fn FnEventNotify)
- func (s *DefaultCoapServer) OnObserve(fn FnEventObserve)
- func (s *DefaultCoapServer) OnObserveCancel(fn FnEventObserveCancel)
- func (s *DefaultCoapServer) OnStart(fn FnEventStart)
- func (s *DefaultCoapServer) Options(path string, fn RouteHandler) Route
- func (s *DefaultCoapServer) Patch(path string, fn RouteHandler) Route
- func (s *DefaultCoapServer) Post(path string, fn RouteHandler) Route
- func (s *DefaultCoapServer) ProxyOverCoap(enabled bool)
- func (s *DefaultCoapServer) ProxyOverHttp(enabled bool)
- func (s *DefaultCoapServer) Put(path string, fn RouteHandler) Route
- func (s *DefaultCoapServer) RemoveObservation(resource string, addr net.Addr)
- func (s *DefaultCoapServer) SetProxyFilter(fn ProxyFilter)
- func (s *DefaultCoapServer) Stop()
- type DefaultResponse
- type EmptyPayload
- type EventCode
- type Events
- type FnEventBlockMessage
- type FnEventClose
- type FnEventDiscover
- type FnEventError
- type FnEventMessage
- type FnEventNotify
- type FnEventObserve
- type FnEventObserveCancel
- type FnEventStart
- type JSONPayload
- type MediaType
- type Message
- func BadGatewayMessage(messageID uint16, messageType uint8) Message
- func BadOptionMessage(messageID uint16, messageType uint8) Message
- func BadRequestMessage(messageID uint16, messageType uint8) Message
- func BytesToMessage(data []byte) (Message, error)
- func ChangedMessage(messageID uint16, messageType uint8) Message
- func ConflictMessage(messageID uint16, messageType uint8) Message
- func ContentMessage(messageID uint16, messageType uint8) Message
- func ContinueMessage(messageID uint16, messageType uint8) Message
- func CreatedMessage(messageID uint16, messageType uint8) Message
- func DeletedMessage(messageID uint16, messageType uint8) Message
- func EmptyMessage(messageID uint16, messageType uint8) Message
- func ForbiddenMessage(messageID uint16, messageType uint8) Message
- func GatewayTimeoutMessage(messageID uint16, messageType uint8) Message
- func InternalServerErrorMessage(messageID uint16, messageType uint8) Message
- func MethodNotAllowedMessage(messageID uint16, messageType uint8) Message
- func NewEmptyMessage(id uint16) Message
- func NewMessage(messageType uint8, code CoapCode, messageID uint16) Message
- func NewMessageOfType(t uint8, id uint16, payload MessagePayload) Message
- func NotAcceptableMessage(messageID uint16, messageType uint8) Message
- func NotFoundMessage(messageID uint16, messageType uint8, token []byte) (m Message)
- func NotImplementedMessage(messageID uint16, messageType uint8) Message
- func PreconditionFailedMessage(messageID uint16, messageType uint8) Message
- func ProxyingNotSupportedMessage(messageID uint16, messageType uint8) Message
- func RequestEntityTooLargeMessage(messageID uint16, messageType uint8) Message
- func ServiceUnavailableMessage(messageID uint16, messageType uint8) Message
- func UnauthorizedMessage(messageID uint16, messageType uint8) Message
- func UnsupportedContentFormatMessage(messageID uint16, messageType uint8) Message
- func ValidMessage(messageID uint16, messageType uint8) Message
- type MessagePayload
- type NilResponse
- type Observation
- type ObserveMessage
- type Option
- type OptionCode
- type PlainTextPayload
- type ProxyFilter
- type ProxyHandler
- type RegExRoute
- type Request
- func NewClientRequestFromMessage(msg Message, attrs map[string]string, session Session) Request
- func NewConfirmableDeleteRequest() Request
- func NewConfirmableGetRequest() Request
- func NewConfirmablePostRequest() Request
- func NewConfirmablePutRequest() Request
- func NewRequest(messageType uint8, messageMethod CoapCode) Request
- func NewRequestFromMessage(msg Message) Request
- func NewRequestWithMessageId(messageType uint8, messageMethod CoapCode, messageID uint16) Request
- type Response
- type Route
- type RouteHandler
- type ServerConfiguration
- type ServerConnection
- type ServerDtlsContext
- type ServerEvents
- func (ce *ServerEvents) BlockMessage(msg Message, inbound bool)
- func (ce *ServerEvents) Closed(server CoapServer)
- func (ce *ServerEvents) Discover()
- func (ce *ServerEvents) Error(err error)
- func (ce *ServerEvents) Message(msg Message, inbound bool)
- func (ce *ServerEvents) Notify(resource string, value interface{}, msg Message)
- func (ce *ServerEvents) Observe(resource string, msg Message)
- func (ce *ServerEvents) ObserveCancelled(resource string, msg Message)
- func (ce *ServerEvents) OnBlockMessage(fn FnEventBlockMessage)
- func (ce *ServerEvents) OnClose(fn FnEventClose)
- func (ce *ServerEvents) OnDiscover(fn FnEventDiscover)
- func (ce *ServerEvents) OnError(fn FnEventError)
- func (ce *ServerEvents) OnMessage(fn FnEventMessage)
- func (ce *ServerEvents) OnNotify(fn FnEventNotify)
- func (ce *ServerEvents) OnObserve(fn FnEventObserve)
- func (ce *ServerEvents) OnObserveCancel(fn FnEventObserveCancel)
- func (ce *ServerEvents) OnStart(fn FnEventStart)
- func (ce *ServerEvents) Started(server CoapServer)
- type Session
- type SortOptions
- type UDPConnection
- func (c *UDPConnection) CancelObserveResource(resource string, token string) (err error)
- func (c *UDPConnection) Close() error
- func (c *UDPConnection) Observe(ch chan ObserveMessage)
- func (c *UDPConnection) ObserveResource(resource string) (tok string, err error)
- func (c *UDPConnection) Read(b []byte) (int, error)
- func (c *UDPConnection) Send(req Request) (resp Response, err error)
- func (c *UDPConnection) SendMessage(msg Message) (resp Response, err error)
- func (c *UDPConnection) StopObserve(ch chan ObserveMessage)
- func (c *UDPConnection) Write(b []byte) (int, error)
- type UDPServerConnection
- func (uc *UDPServerConnection) Close() error
- func (uc *UDPServerConnection) LocalAddr() net.Addr
- func (uc *UDPServerConnection) ReadFrom(b []byte) (n int, addr net.Addr, err error)
- func (uc *UDPServerConnection) SetDeadline(t time.Time) error
- func (uc *UDPServerConnection) SetReadDeadline(t time.Time) error
- func (uc *UDPServerConnection) SetWriteDeadline(t time.Time) error
- func (uc *UDPServerConnection) WriteTo(b []byte, addr net.Addr) (n int, err error)
- type UDPServerSession
- func (s *UDPServerSession) GetAddress() net.Addr
- func (s *UDPServerSession) GetConnection() ServerConnection
- func (s *UDPServerSession) GetServer() CoapServer
- func (s *UDPServerSession) Read(b []byte) (n int, err error)
- func (s *UDPServerSession) Write(b []byte) (n int, err error)
- func (s *UDPServerSession) WriteBuffer(b []byte) (n int)
- type XMLPayload
Constants ¶
const ( MessageConfirmable = 0 MessageNonConfirmable = 1 MessageAcknowledgment = 2 MessageReset = 3 )
Types of Messages
const ( DataHeader = 0 DataCode = 1 DataMsgIDStart = 2 DataMsgIDEnd = 4 DataTokenStart = 4 )
Fragments/parts of a CoAP Message packet
const ( MethodGet = "GET" MethodPut = "PUT" MethodPost = "POST" MethodDelete = "DELETE" MethodOptions = "OPTIONS" MethodPatch = "PATCH" )
const ( SecNoSec = "NoSec" SecRawPublicKey = "RawPublicKey" SecCertificate = "Certificate" )
Security Options
const CoapDefaultHost = ""
const CoapDefaultPort = 5683
const CoapsDefaultPort = 5684
const DefaultAckRandomFactor = 1.5
const DefaultAckTimeout = 2
const DefaultLeisure = 5
const DefaultMaxRetransmit = 4
const DefaultNStart = 1
const DefaultProbingRate = 1
const MaxPacketSize = 1500
const MessageIDPurgeDuration = 60
MessageIDPurgeDuration defines the number of seconds before a MessageID Purge is initiated
const PayloadMarker = 0xff
const UDP = "udp"
Variables ¶
var CurrentMessageID = 0
CurrentMessageID stores the current message id used/generated for messages
var DTLS_CLIENT_CONNECTIONS = make(map[int32]*DTLSConnection)
var DTLS_SERVER_SESSIONS = make(map[int32]*DTLSServerSession)
var ErrInvalidCoapVersion = errors.New("Invalid CoAP version. Should be 1.")
var ErrInvalidTokenLength = errors.New("Invalid Token Length ( > 8)")
var ErrMessageSizeTooLongBlockOptionValNotSet = errors.New("Message is too long, block option or value not set")
var ErrNilAddr = errors.New("Address cannot be nil")
var ErrNilConn = errors.New("Connection object is nil")
var ErrNilMessage = errors.New("Message is nil")
var ErrNoMatchingMethod = errors.New("No matching method")
var ErrNoMatchingRoute = errors.New("No matching route found")
var ErrOptionDeltaUsesValue15 = errors.New(("Message format error. Option delta has reserved value of 15"))
var ErrOptionLengthUsesValue15 = errors.New(("Message format error. Option length has reserved value of 15"))
var ErrPacketLengthLessThan4 = errors.New("Packet length less than 4 bytes")
Errors
var ErrUnknownCriticalOption = errors.New("Unknown critical option encountered")
var ErrUnknownMessageType = errors.New("Unknown message type")
var ErrUnsupportedContentFormat = errors.New("Unsupported Content-Format")
var ErrUnsupportedMethod = errors.New("Unsupported Method")
var GENERATE_ID uint16 = 0
var MESSAGEID_MUTEX *sync.Mutex
var NEXT_SESSION_ID int32 = 0
Functions ¶
func AddResponseChannel ¶
func AddResponseChannel(c CoapServer, msgId uint16, ch chan *CoapResponseChannel)
func COAPProxyHandler ¶
func COAPProxyHandler(c CoapServer, msg Message, session Session)
func CoapCodeToString ¶
CoapCodeToString returns the string representation of a CoapCode
func DeleteResponseChannel ¶
func DeleteResponseChannel(c CoapServer, msgId uint16)
func GenerateMessageID ¶
func GenerateMessageID() uint16
GenerateMessageId generate a uint16 Message ID
func GenerateToken ¶
GenerateToken generates a random token by a given length
func GetResponseChannel ¶
func GetResponseChannel(c CoapServer, msgId uint16) (ch chan *CoapResponseChannel)
func HTTPCOAPProxyHandler ¶
Handles requests for proxying from HTTP to CoAP
func HTTPProxyHandler ¶
func HTTPProxyHandler(c CoapServer, msg Message, session Session)
Handles requests for proxying from CoAP to HTTP
func IsProxyRequest ¶
Determines if a message contains options for proxying (i.e. Proxy-Scheme or Proxy-Uri)
func IsRepeatableOption ¶
Checks if an option is repeatable
func IsValidOption ¶
Checks if an option/option code is recognizable/valid
func MessageSizeAllowed ¶
func MessageToBytes ¶
Converts a message object to a byte array. Typically done prior to transmission
func MethodString ¶
Gets the string representation of a CoAP Method code (e.g. GET, PUT, DELETE etc)
func NewResponseChannel ¶
func NewResponseChannel() (ch chan *CoapResponseChannel)
func NullProxyHandler ¶
func NullProxyHandler(c CoapServer, msg Message, session Session)
The default handler when proxying is disabled
func OptionNumberToString ¶
func OptionNumberToString(o OptionCode) string
OptionNumberToString returns the string representation of a given Option Code
func PayloadAsString ¶
func PayloadAsString(p MessagePayload) string
Returns the string value for a Message Payload
func PrintOptions ¶
func PrintOptions(msg Message)
PrintOptions pretty prints out a given Message's options
func ValidCoapMediaTypeCode ¶
ValidCoapMediaTypeCode Checks if a MediaType is of a valid code
func ValidateMessage ¶
Validates a message object and returns any error upon validation failure
Types ¶
type Block1Option ¶
type Block1Option struct {
CoapOption
}
func Block1OptionFromOption ¶
func Block1OptionFromOption(opt Option) *Block1Option
func NewBlock1Option ¶
func NewBlock1Option(bs BlockSizeType, more bool, seq uint32) *Block1Option
func (*Block1Option) BlockSizeLength ¶
func (o *Block1Option) BlockSizeLength() uint32
func (*Block1Option) Exponent ¶
func (o *Block1Option) Exponent() uint32
func (*Block1Option) HasMore ¶
func (o *Block1Option) HasMore() bool
func (*Block1Option) Sequence ¶
func (o *Block1Option) Sequence() uint32
func (*Block1Option) Size ¶
func (o *Block1Option) Size() BlockSizeType
type BlockMessage ¶
type BlockMessage interface { }
func NewBlockMessage ¶
func NewBlockMessage() BlockMessage
type BlockSizeType ¶
type BlockSizeType byte
const ( BlockSize16 BlockSizeType = 0 BlockSize32 BlockSizeType = 1 BlockSize64 BlockSizeType = 2 BlockSize128 BlockSizeType = 3 BlockSize256 BlockSizeType = 4 BlockSize512 BlockSizeType = 5 BlockSize1024 BlockSizeType = 6 )
type BySequence ¶
type BySequence []*CoapBlockMessage
func (BySequence) Len ¶
func (o BySequence) Len() int
func (BySequence) Less ¶
func (o BySequence) Less(i, j int) bool
func (BySequence) Swap ¶
func (o BySequence) Swap(i, j int)
type BytesPayload ¶
type BytesPayload struct {
// contains filtered or unexported fields
}
func (*BytesPayload) GetBytes ¶
func (p *BytesPayload) GetBytes() []byte
func (*BytesPayload) Length ¶
func (p *BytesPayload) Length() int
func (*BytesPayload) String ¶
func (p *BytesPayload) String() string
type CoapBlockMessage ¶
type CoapBlockMessage struct { CoapMessage MessageBuf []byte Sequence uint32 }
type CoapCode ¶
type CoapCode uint8
CoapCode defines a valid CoAP Code Type
const ( Get CoapCode = 1 Post CoapCode = 2 Put CoapCode = 3 Delete CoapCode = 4 // 2.x CoapCodeEmpty CoapCode = 0 CoapCodeCreated CoapCode = 65 // 2.01 CoapCodeDeleted CoapCode = 66 // 2.02 CoapCodeValid CoapCode = 67 // 2.03 CoapCodeChanged CoapCode = 68 // 2.04 CoapCodeContent CoapCode = 69 // 2.05 CoapCodeContinue CoapCode = 95 // 2.31 // 4.x CoapCodeBadRequest CoapCode = 128 // 4.00 CoapCodeBadOption CoapCode = 130 // 4.02 CoapCodeForbidden CoapCode = 131 // 4.03 CoapCodeNotFound CoapCode = 132 // 4.04 CoapCodeMethodNotAllowed CoapCode = 133 // 4.05 CoapCodeNotAcceptable CoapCode = 134 // 4.06 CoapCodeRequestEntityIncomplete CoapCode = 136 // 4.08 CoapCodeConflict CoapCode = 137 // 4.09 CoapCodePreconditionFailed CoapCode = 140 // 4.12 CoapCodeRequestEntityTooLarge CoapCode = 141 // 4.13 CoapCodeUnsupportedContentFormat CoapCode = 143 // 4.15 // 5.x CoapCodeInternalServerError CoapCode = 160 // 5.00 CoapCodeNotImplemented CoapCode = 161 // 5.01 CoapCodeBadGateway CoapCode = 162 // 5.02 CoapCodeGatewayTimeout CoapCode = 164 // 5.04 CoapCodeProxyingNotSupported CoapCode = 165 // 5.05 )
type CoapMessage ¶
type CoapMessage struct { MessageType uint8 Code CoapCode MessageID uint16 Payload MessagePayload Token []byte Options []Option }
A Message object represents a CoAP payload
func (*CoapMessage) AddOption ¶
func (m *CoapMessage) AddOption(code OptionCode, value interface{})
Add an Option to the message. If an option is not repeatable, it will replace any existing defined Option of the same type
func (*CoapMessage) AddOptions ¶
func (m *CoapMessage) AddOptions(opts []Option)
Add an array of Options to the message. If an option is not repeatable, it will replace any existing defined Option of the same type
func (*CoapMessage) CloneOptions ¶
func (m *CoapMessage) CloneOptions(cm Message, opts ...OptionCode)
Copies the given list of options from another message to this one
func (*CoapMessage) GetAcceptedContent ¶
func (m *CoapMessage) GetAcceptedContent() MediaType
func (*CoapMessage) GetAllOptions ¶
func (m *CoapMessage) GetAllOptions() []Option
func (*CoapMessage) GetCode ¶
func (m *CoapMessage) GetCode() CoapCode
func (*CoapMessage) GetCodeString ¶
func (m *CoapMessage) GetCodeString() string
func (*CoapMessage) GetLocationPath ¶
func (m *CoapMessage) GetLocationPath() string
Returns the string value of the Location Path Options by joining and defining a / separator
func (*CoapMessage) GetMessageId ¶
func (m *CoapMessage) GetMessageId() uint16
func (*CoapMessage) GetMessageType ¶
func (m *CoapMessage) GetMessageType() uint8
func (*CoapMessage) GetMethod ¶
func (m *CoapMessage) GetMethod() uint8
func (CoapMessage) GetOption ¶
func (m CoapMessage) GetOption(id OptionCode) Option
Returns the first option found for a given option code
func (CoapMessage) GetOptions ¶
func (m CoapMessage) GetOptions(id OptionCode) []Option
Returns an array of options given an option code
func (CoapMessage) GetOptionsAsString ¶
func (m CoapMessage) GetOptionsAsString(id OptionCode) []string
Attempts to return the string value of an Option
func (*CoapMessage) GetPayload ¶
func (m *CoapMessage) GetPayload() MessagePayload
func (*CoapMessage) GetToken ¶
func (m *CoapMessage) GetToken() []byte
func (*CoapMessage) GetTokenLength ¶
func (m *CoapMessage) GetTokenLength() uint8
func (*CoapMessage) GetTokenString ¶
func (m *CoapMessage) GetTokenString() string
func (CoapMessage) GetURIPath ¶
func (m CoapMessage) GetURIPath() string
Returns the string value of the Uri Path Options by joining and defining a / separator
func (*CoapMessage) RemoveOptions ¶
func (m *CoapMessage) RemoveOptions(id OptionCode)
Removes an Option
func (*CoapMessage) ReplaceOptions ¶
func (m *CoapMessage) ReplaceOptions(code OptionCode, opts []Option)
Replace an Option
func (*CoapMessage) SetBlock1Option ¶
func (c *CoapMessage) SetBlock1Option(opt Option)
func (*CoapMessage) SetMessageId ¶
func (m *CoapMessage) SetMessageId(id uint16)
func (*CoapMessage) SetMessageType ¶
func (m *CoapMessage) SetMessageType(t uint8)
func (*CoapMessage) SetPayload ¶
func (m *CoapMessage) SetPayload(p MessagePayload)
func (*CoapMessage) SetStringPayload ¶
func (m *CoapMessage) SetStringPayload(s string)
Adds a string payload
func (*CoapMessage) SetToken ¶
func (m *CoapMessage) SetToken(t []byte)
type CoapObserveMessage ¶
type CoapObserveMessage struct { CoapMessage Resource string Value interface{} Msg Message }
func (*CoapObserveMessage) GetMessage ¶
func (m *CoapObserveMessage) GetMessage() Message
func (*CoapObserveMessage) GetResource ¶
func (m *CoapObserveMessage) GetResource() string
func (*CoapObserveMessage) GetValue ¶
func (m *CoapObserveMessage) GetValue() interface{}
type CoapOption ¶
type CoapOption struct { Code OptionCode Value interface{} }
Represents an Option for a CoAP Message
func NewOption ¶
func NewOption(optionNumber OptionCode, optionValue interface{}) *CoapOption
Instantiates a New Option
func (*CoapOption) GetCode ¶
func (o *CoapOption) GetCode() OptionCode
func (*CoapOption) GetValue ¶
func (o *CoapOption) GetValue() interface{}
func (*CoapOption) IntValue ¶
func (o *CoapOption) IntValue() int
func (*CoapOption) IsCritical ¶
func (o *CoapOption) IsCritical() bool
Determines if an option is critical
func (*CoapOption) IsElective ¶
func (o *CoapOption) IsElective() bool
Determines if an option is elective
func (*CoapOption) Name ¶
func (o *CoapOption) Name() string
func (*CoapOption) StringValue ¶
func (o *CoapOption) StringValue() string
Returns the string value of an option
type CoapRequest ¶
type CoapRequest struct {
// contains filtered or unexported fields
}
Wraps a CoAP Message as a Request Provides various methods which proxies the Message object methods
func (*CoapRequest) GetAttribute ¶
func (c *CoapRequest) GetAttribute(o string) string
func (*CoapRequest) GetAttributeAsInt ¶
func (c *CoapRequest) GetAttributeAsInt(o string) int
func (*CoapRequest) GetAttributes ¶
func (c *CoapRequest) GetAttributes() map[string]string
func (*CoapRequest) GetMessage ¶
func (c *CoapRequest) GetMessage() Message
func (*CoapRequest) GetSession ¶
func (c *CoapRequest) GetSession() Session
func (*CoapRequest) GetURIQuery ¶
func (c *CoapRequest) GetURIQuery(q string) string
func (*CoapRequest) SetConfirmable ¶
func (c *CoapRequest) SetConfirmable(con bool)
func (*CoapRequest) SetMediaType ¶
func (c *CoapRequest) SetMediaType(mt MediaType)
func (*CoapRequest) SetPayload ¶
func (c *CoapRequest) SetPayload(b []byte)
func (*CoapRequest) SetProxyURI ¶
func (c *CoapRequest) SetProxyURI(uri string)
func (*CoapRequest) SetRequestURI ¶
func (c *CoapRequest) SetRequestURI(uri string)
func (*CoapRequest) SetStringPayload ¶
func (c *CoapRequest) SetStringPayload(s string)
func (*CoapRequest) SetToken ¶
func (c *CoapRequest) SetToken(t string)
func (*CoapRequest) SetURIQuery ¶
func (c *CoapRequest) SetURIQuery(k string, v string)
type CoapResponseChannel ¶
type CoapServer ¶
type CoapServer interface { ListenAndServe(addr string) ListenAndServeDTLS(addr string) Stop() Get(path string, fn RouteHandler) Route Delete(path string, fn RouteHandler) Route Put(path string, fn RouteHandler) Route Post(path string, fn RouteHandler) Route Options(path string, fn RouteHandler) Route Patch(path string, fn RouteHandler) Route NewRoute(path string, method CoapCode, fn RouteHandler) Route NotifyChange(resource, value string, confirm bool) OnNotify(fn FnEventNotify) OnStart(fn FnEventStart) OnClose(fn FnEventClose) OnDiscover(fn FnEventDiscover) OnError(fn FnEventError) OnObserve(fn FnEventObserve) OnObserveCancel(fn FnEventObserveCancel) OnMessage(fn FnEventMessage) OnBlockMessage(fn FnEventBlockMessage) ProxyOverHttp(enabled bool) ProxyOverCoap(enabled bool) GetEvents() Events AllowProxyForwarding(Message, net.Addr) bool GetRoutes() []Route ForwardCoap(msg Message, session Session) ForwardHTTP(msg Message, session Session) AddObservation(resource, token string, session Session) HasObservation(resource string, addr net.Addr) bool RemoveObservation(resource string, addr net.Addr) HandlePSK(func(id string) []byte) GetSession(addr string) Session DeleteSession(ssn Session) GetCookieSecret() []byte }
Interfaces
func NewServer ¶
func NewServer() CoapServer
type Connection ¶
type Connection interface { ObserveResource(resource string) (tok string, err error) CancelObserveResource(resource string, token string) (err error) StopObserve(ch chan ObserveMessage) Observe(ch chan ObserveMessage) Send(req Request) (resp Response, err error) Write(b []byte) (n int, err error) Read(b []byte) (n int, err error) Close() error }
func Dial ¶
func Dial(address string) (conn Connection, err error)
func DialDTLS ¶
func DialDTLS(address, identity, psk string) (conn Connection, err error)
func NewDTLSConnection ¶
func NewDTLSConnection(c net.Conn, identity, psk string) (conn Connection, err error)
Client DTLS
type CoreAttribute ¶
type CoreAttribute struct { Key string Value interface{} }
func NewCoreAttribute ¶
func NewCoreAttribute(key string, value interface{}) *CoreAttribute
Instantiates a new core-attribute with a given key/value
type CoreAttributes ¶
type CoreAttributes []*CoreAttribute
type CoreLinkFormatPayload ¶
type CoreLinkFormatPayload struct { }
Represents a message payload containing core-link format values
func (*CoreLinkFormatPayload) GetBytes ¶
func (p *CoreLinkFormatPayload) GetBytes() []byte
func (*CoreLinkFormatPayload) Length ¶
func (p *CoreLinkFormatPayload) Length() int
func (*CoreLinkFormatPayload) String ¶
func (p *CoreLinkFormatPayload) String() string
type CoreResource ¶
type CoreResource struct { Target string Attributes CoreAttributes }
func CoreResourcesFromString ¶
func CoreResourcesFromString(str string) []*CoreResource
CoreResourcesFromString Converts to CoRE Resources Object from a CoRE String
func (*CoreResource) AddAttribute ¶
func (c *CoreResource) AddAttribute(key string, value interface{})
Adds an attribute (key/value) for a given core resource
func (*CoreResource) GetAttribute ¶
func (c *CoreResource) GetAttribute(key string) *CoreAttribute
Gets an attribute for a core resource
type DTLSConnection ¶
type DTLSConnection struct { UDPConnection // contains filtered or unexported fields }
func (*DTLSConnection) CancelObserveResource ¶
func (c *DTLSConnection) CancelObserveResource(resource string, token string) (err error)
func (*DTLSConnection) Close ¶
func (c *DTLSConnection) Close() error
func (*DTLSConnection) Observe ¶
func (c *DTLSConnection) Observe(ch chan ObserveMessage)
func (*DTLSConnection) ObserveResource ¶
func (c *DTLSConnection) ObserveResource(resource string) (tok string, err error)
func (*DTLSConnection) StopObserve ¶
func (c *DTLSConnection) StopObserve(ch chan ObserveMessage)
type DTLSServerSession ¶
type DTLSServerSession struct { UDPServerSession // contains filtered or unexported fields }
func (*DTLSServerSession) GetConnection ¶
func (s *DTLSServerSession) GetConnection() ServerConnection
type DefaultCoapServer ¶
type DefaultCoapServer struct {
// contains filtered or unexported fields
}
func (*DefaultCoapServer) AddObservation ¶
func (s *DefaultCoapServer) AddObservation(resource, token string, session Session)
func (*DefaultCoapServer) AllowProxyForwarding ¶
func (s *DefaultCoapServer) AllowProxyForwarding(msg Message, addr net.Addr) bool
func (*DefaultCoapServer) Delete ¶
func (s *DefaultCoapServer) Delete(path string, fn RouteHandler) Route
func (*DefaultCoapServer) DeleteSession ¶
func (s *DefaultCoapServer) DeleteSession(ssn Session)
func (*DefaultCoapServer) ForwardCoap ¶
func (s *DefaultCoapServer) ForwardCoap(msg Message, session Session)
func (*DefaultCoapServer) ForwardHTTP ¶
func (s *DefaultCoapServer) ForwardHTTP(msg Message, session Session)
func (*DefaultCoapServer) Get ¶
func (s *DefaultCoapServer) Get(path string, fn RouteHandler) Route
func (*DefaultCoapServer) GetCookieSecret ¶
func (s *DefaultCoapServer) GetCookieSecret() []byte
func (*DefaultCoapServer) GetEvents ¶
func (s *DefaultCoapServer) GetEvents() Events
func (*DefaultCoapServer) GetRoutes ¶
func (s *DefaultCoapServer) GetRoutes() []Route
func (*DefaultCoapServer) GetSession ¶
func (s *DefaultCoapServer) GetSession(addr string) Session
func (*DefaultCoapServer) HandlePSK ¶
func (s *DefaultCoapServer) HandlePSK(fn func(id string) []byte)
func (*DefaultCoapServer) HasObservation ¶
func (s *DefaultCoapServer) HasObservation(resource string, addr net.Addr) bool
func (*DefaultCoapServer) ListenAndServe ¶
func (s *DefaultCoapServer) ListenAndServe(addr string)
func (*DefaultCoapServer) ListenAndServeDTLS ¶
func (s *DefaultCoapServer) ListenAndServeDTLS(addr string)
func (*DefaultCoapServer) NewRoute ¶
func (s *DefaultCoapServer) NewRoute(path string, method CoapCode, fn RouteHandler) Route
func (*DefaultCoapServer) NotifyChange ¶
func (s *DefaultCoapServer) NotifyChange(resource, value string, confirm bool)
func (*DefaultCoapServer) OnBlockMessage ¶
func (s *DefaultCoapServer) OnBlockMessage(fn FnEventBlockMessage)
func (*DefaultCoapServer) OnClose ¶
func (s *DefaultCoapServer) OnClose(fn FnEventClose)
func (*DefaultCoapServer) OnDiscover ¶
func (s *DefaultCoapServer) OnDiscover(fn FnEventDiscover)
func (*DefaultCoapServer) OnError ¶
func (s *DefaultCoapServer) OnError(fn FnEventError)
func (*DefaultCoapServer) OnMessage ¶
func (s *DefaultCoapServer) OnMessage(fn FnEventMessage)
func (*DefaultCoapServer) OnNotify ¶
func (s *DefaultCoapServer) OnNotify(fn FnEventNotify)
func (*DefaultCoapServer) OnObserve ¶
func (s *DefaultCoapServer) OnObserve(fn FnEventObserve)
func (*DefaultCoapServer) OnObserveCancel ¶
func (s *DefaultCoapServer) OnObserveCancel(fn FnEventObserveCancel)
func (*DefaultCoapServer) OnStart ¶
func (s *DefaultCoapServer) OnStart(fn FnEventStart)
func (*DefaultCoapServer) Options ¶
func (s *DefaultCoapServer) Options(path string, fn RouteHandler) Route
func (*DefaultCoapServer) Patch ¶
func (s *DefaultCoapServer) Patch(path string, fn RouteHandler) Route
func (*DefaultCoapServer) Post ¶
func (s *DefaultCoapServer) Post(path string, fn RouteHandler) Route
func (*DefaultCoapServer) ProxyOverCoap ¶
func (s *DefaultCoapServer) ProxyOverCoap(enabled bool)
func (*DefaultCoapServer) ProxyOverHttp ¶
func (s *DefaultCoapServer) ProxyOverHttp(enabled bool)
func (*DefaultCoapServer) Put ¶
func (s *DefaultCoapServer) Put(path string, fn RouteHandler) Route
func (*DefaultCoapServer) RemoveObservation ¶
func (s *DefaultCoapServer) RemoveObservation(resource string, addr net.Addr)
func (*DefaultCoapServer) SetProxyFilter ¶
func (s *DefaultCoapServer) SetProxyFilter(fn ProxyFilter)
func (*DefaultCoapServer) Stop ¶
func (s *DefaultCoapServer) Stop()
type DefaultResponse ¶
type DefaultResponse struct {
// contains filtered or unexported fields
}
func (*DefaultResponse) GetError ¶
func (c *DefaultResponse) GetError() error
func (*DefaultResponse) GetMessage ¶
func (c *DefaultResponse) GetMessage() Message
func (*DefaultResponse) GetPayload ¶
func (c *DefaultResponse) GetPayload() []byte
func (*DefaultResponse) GetURIQuery ¶
func (c *DefaultResponse) GetURIQuery(q string) string
type EmptyPayload ¶
type EmptyPayload struct { }
Represents an empty message payload
func (*EmptyPayload) GetBytes ¶
func (p *EmptyPayload) GetBytes() []byte
func (*EmptyPayload) Length ¶
func (p *EmptyPayload) Length() int
func (*EmptyPayload) String ¶
func (p *EmptyPayload) String() string
type Events ¶
type Events interface { OnNotify(fn FnEventNotify) OnStart(fn FnEventStart) OnClose(fn FnEventClose) OnDiscover(fn FnEventDiscover) OnError(fn FnEventError) OnObserve(fn FnEventObserve) OnObserveCancel(fn FnEventObserveCancel) OnMessage(fn FnEventMessage) OnBlockMessage(fn FnEventBlockMessage) Notify(resource string, value interface{}, msg Message) Started(server CoapServer) Closed(server CoapServer) Discover() Error(err error) Observe(resource string, msg Message) ObserveCancelled(resource string, msg Message) Message(msg Message, inbound bool) BlockMessage(msg Message, inbound bool) }
type FnEventBlockMessage ¶
type FnEventClose ¶
type FnEventClose func(CoapServer)
type FnEventDiscover ¶
type FnEventDiscover func()
type FnEventError ¶
type FnEventError func(error)
type FnEventMessage ¶
type FnEventNotify ¶
type FnEventObserve ¶
type FnEventObserveCancel ¶
type FnEventStart ¶
type FnEventStart func(CoapServer)
type JSONPayload ¶
type JSONPayload struct {
// contains filtered or unexported fields
}
Represents a message payload containing JSON String
func (*JSONPayload) GetBytes ¶
func (p *JSONPayload) GetBytes() []byte
func (*JSONPayload) Length ¶
func (p *JSONPayload) Length() int
func (*JSONPayload) String ¶
func (p *JSONPayload) String() string
type MediaType ¶
type MediaType int
const ( MediaTypeTextPlain MediaType = 0 MediaTypeTextXML MediaType = 1 MediaTypeTextCsv MediaType = 2 MediaTypeTextHTML MediaType = 3 MediaTypeImageGif MediaType = 21 MediaTypeImageJpeg MediaType = 22 MediaTypeImagePng MediaType = 23 MediaTypeImageTiff MediaType = 24 MediaTypeAudioRaw MediaType = 25 MediaTypeVideoRaw MediaType = 26 MediaTypeApplicationLinkFormat MediaType = 40 MediaTypeApplicationXML MediaType = 41 MediaTypeApplicationOctetStream MediaType = 42 MediaTypeApplicationRdfXML MediaType = 43 MediaTypeApplicationSoapXML MediaType = 44 MediaTypeApplicationAtomXML MediaType = 45 MediaTypeApplicationXmppXML MediaType = 46 MediaTypeApplicationExi MediaType = 47 MediaTypeApplicationFastInfoSet MediaType = 48 MediaTypeApplicationSoapFastInfoSet MediaType = 49 MediaTypeApplicationJSON MediaType = 50 MediaTypeApplicationXObitBinary MediaType = 51 MediaTypeTextPlainVndOmaLwm2m MediaType = 1541 MediaTypeTlvVndOmaLwm2m MediaType = 1542 MediaTypeJSONVndOmaLwm2m MediaType = 1543 MediaTypeOpaqueVndOmaLwm2m MediaType = 1544 )
type Message ¶
type Message interface { GetToken() []byte GetMessageId() uint16 GetMessageType() uint8 GetAcceptedContent() MediaType GetCodeString() string GetCode() CoapCode GetMethod() uint8 GetTokenLength() uint8 GetTokenString() string GetOptions(id OptionCode) []Option GetOption(id OptionCode) Option GetAllOptions() []Option GetOptionsAsString(id OptionCode) []string GetLocationPath() string GetURIPath() string GetPayload() MessagePayload SetToken([]byte) SetMessageId(uint16) SetMessageType(uint8) SetBlock1Option(opt Option) SetStringPayload(s string) SetPayload(MessagePayload) AddOption(code OptionCode, value interface{}) AddOptions(opts []Option) CloneOptions(cm Message, opts ...OptionCode) ReplaceOptions(code OptionCode, opts []Option) RemoveOptions(id OptionCode) }
func BadGatewayMessage ¶
Creates a Non-Confirmable with CoAP Code 502 - Bad Gateway
func BadOptionMessage ¶
Creates a Non-Confirmable with CoAP Code 402 - Bad Option
func BadRequestMessage ¶
Creates a Non-Confirmable with CoAP Code 400 - Bad Request
func BytesToMessage ¶
Converts an array of bytes to a Mesasge object. An error is returned if a parsing error occurs
func ChangedMessage ¶
Creates a Non-Confirmable with CoAP Code 204 - Changed
func ConflictMessage ¶
Creates a Non-Confirmable with CoAP Code 409 - Conflict
func ContentMessage ¶
Creates a Non-Confirmable with CoAP Code 205 - Content
func ContinueMessage ¶
func CreatedMessage ¶
Creates a Non-Confirmable with CoAP Code 201 - Created
func DeletedMessage ¶
// Creates a Non-Confirmable with CoAP Code 202 - Deleted
func EmptyMessage ¶
Response Code Messages Creates a Non-Confirmable Empty Message
func ForbiddenMessage ¶
Creates a Non-Confirmable with CoAP Code 403 - Forbidden
func GatewayTimeoutMessage ¶
Creates a Non-Confirmable with CoAP Code 504 - Gateway Timeout
func InternalServerErrorMessage ¶
Creates a Non-Confirmable with CoAP Code 500 - Internal Server Error
func MethodNotAllowedMessage ¶
Creates a Non-Confirmable with CoAP Code 405 - Method Not Allowed
func NewEmptyMessage ¶
Instantiates an empty message with a given message id
func NewMessage ¶
Instantiates a new message object messageType (e.g. Confirm/Non-Confirm) CoAP code 404 - Not found etc Message ID uint16 unique id
func NewMessageOfType ¶
func NewMessageOfType(t uint8, id uint16, payload MessagePayload) Message
Instantiates an empty message of a specific type and message id
func NotAcceptableMessage ¶
Creates a Non-Confirmable with CoAP Code 406 - Not Acceptable
func NotFoundMessage ¶
Creates a Non-Confirmable with CoAP Code 404 - Not Found
func NotImplementedMessage ¶
Creates a Non-Confirmable with CoAP Code 501 - Not Implemented
func PreconditionFailedMessage ¶
Creates a Non-Confirmable with CoAP Code 412 - Precondition Failed
func ProxyingNotSupportedMessage ¶
Creates a Non-Confirmable with CoAP Code 505 - Proxying Not Supported
func RequestEntityTooLargeMessage ¶
Creates a Non-Confirmable with CoAP Code 413 - Request Entity Too Large
func ServiceUnavailableMessage ¶
Creates a Non-Confirmable with CoAP Code 503 - Service Unavailable
func UnauthorizedMessage ¶
Creates a Non-Confirmable with CoAP Code 401 - Unauthorized
func UnsupportedContentFormatMessage ¶
Creates a Non-Confirmable with CoAP Code 415 - Unsupported Content Format
func ValidMessage ¶
Creates a Non-Confirmable with CoAP Code 203 - Valid
type MessagePayload ¶
Represents the payload/content of a CoAP Message
func NewBytesPayload ¶
func NewBytesPayload(v []byte) MessagePayload
Represents a message payload containing an array of bytes
func NewEmptyPayload ¶
func NewEmptyPayload() MessagePayload
func NewJSONPayload ¶
func NewJSONPayload(obj interface{}) MessagePayload
func NewPlainTextPayload ¶
func NewPlainTextPayload(s string) MessagePayload
Instantiates a new message payload of type string
type NilResponse ¶
type NilResponse struct { }
func (NilResponse) GetError ¶
func (c NilResponse) GetError() error
func (NilResponse) GetMessage ¶
func (c NilResponse) GetMessage() Message
func (NilResponse) GetPayload ¶
func (c NilResponse) GetPayload() []byte
func (NilResponse) GetURIQuery ¶
func (c NilResponse) GetURIQuery(q string) string
type Observation ¶
func NewObservation ¶
func NewObservation(session Session, token string, resource string) *Observation
type ObserveMessage ¶
func NewObserveMessage ¶
func NewObserveMessage(r string, val interface{}, msg Message) ObserveMessage
type Option ¶
type Option interface { Name() string IsElective() bool IsCritical() bool StringValue() string IntValue() int GetCode() OptionCode GetValue() interface{} }
func NewPathOptions ¶
Creates an array of options decomposed from a given path
type OptionCode ¶
type OptionCode int
OptionCode type represents a valid CoAP Option Code
const ( // OptionIfMatch request-header field is used with a method to make it conditional. // A client that has one or more entities previously obtained from the resource can verify // that one of those entities is current by including a list of their associated entity tags // in the If-Match header field. OptionIfMatch OptionCode = 1 OptionURIHost OptionCode = 3 OptionEtag OptionCode = 4 OptionIfNoneMatch OptionCode = 5 OptionObserve OptionCode = 6 OptionURIPort OptionCode = 7 OptionLocationPath OptionCode = 8 OptionURIPath OptionCode = 11 OptionContentFormat OptionCode = 12 OptionMaxAge OptionCode = 14 OptionURIQuery OptionCode = 15 OptionAccept OptionCode = 17 OptionLocationQuery OptionCode = 20 OptionBlock2 OptionCode = 23 OptionBlock1 OptionCode = 27 OptionSize2 OptionCode = 28 OptionProxyURI OptionCode = 35 OptionProxyScheme OptionCode = 39 OptionSize1 OptionCode = 60 )
type PlainTextPayload ¶
type PlainTextPayload struct {
// contains filtered or unexported fields
}
Represents a message payload containing string value
func (*PlainTextPayload) GetBytes ¶
func (p *PlainTextPayload) GetBytes() []byte
func (*PlainTextPayload) Length ¶
func (p *PlainTextPayload) Length() int
func (*PlainTextPayload) String ¶
func (p *PlainTextPayload) String() string
type ProxyHandler ¶
type ProxyHandler func(c CoapServer, msg Message, session Session)
type RegExRoute ¶
type RegExRoute struct { Path string Method string Handler RouteHandler RegEx *regexp.Regexp AutoAck bool MediaTypes []MediaType }
Route represents a CoAP Route/Resource
func (*RegExRoute) AutoAcknowledge ¶
func (r *RegExRoute) AutoAcknowledge() bool
func (*RegExRoute) GetConfiguredPath ¶
func (r *RegExRoute) GetConfiguredPath() string
func (*RegExRoute) GetMediaTypes ¶
func (r *RegExRoute) GetMediaTypes() []MediaType
func (*RegExRoute) GetMethod ¶
func (r *RegExRoute) GetMethod() string
func (*RegExRoute) Handle ¶
func (r *RegExRoute) Handle(req Request) Response
type Request ¶
type Request interface { GetAttributes() map[string]string GetAttribute(o string) string GetAttributeAsInt(o string) int GetMessage() Message GetURIQuery(q string) string SetProxyURI(uri string) SetMediaType(mt MediaType) SetPayload([]byte) SetStringPayload(s string) SetRequestURI(uri string) SetConfirmable(con bool) SetToken(t string) SetURIQuery(k string, v string) }
func NewConfirmableDeleteRequest ¶
func NewConfirmableDeleteRequest() Request
func NewConfirmableGetRequest ¶
func NewConfirmableGetRequest() Request
func NewConfirmablePostRequest ¶
func NewConfirmablePostRequest() Request
func NewConfirmablePutRequest ¶
func NewConfirmablePutRequest() Request
func NewRequest ¶
Creates a New Request Instance
func NewRequestFromMessage ¶
Creates a new request messages from a CoAP Message
type Response ¶
type Response interface { GetMessage() Message GetError() error GetPayload() []byte GetURIQuery(q string) string }
func NewResponse ¶
Creates a new Response object with a Message object and any error messages
func NewResponseWithMessage ¶
Creates a new response object with a Message object
func NoResponse ¶
func NoResponse() Response
type Route ¶
type Route interface { GetMethod() string GetMediaTypes() []MediaType GetConfiguredPath() string Matches(path string) (bool, map[string]string) AutoAcknowledge() bool Handle(req Request) Response }
func CreateNewRegExRoute ¶
func CreateNewRegExRoute(path string, method string, fn RouteHandler) Route
CreateNewRoute creates a new Route object
type RouteHandler ¶
type ServerConfiguration ¶
type ServerConfiguration struct {
EnableResourceDiscovery bool
}
type ServerConnection ¶
type ServerDtlsContext ¶
type ServerDtlsContext struct {
// contains filtered or unexported fields
}
func NewServerDtlsContext ¶
func NewServerDtlsContext() (ctx *ServerDtlsContext, err error)
type ServerEvents ¶
type ServerEvents struct {
// contains filtered or unexported fields
}
This holds the various events which are triggered throughout an application's lifetime
func NewEvents ¶
func NewEvents() *ServerEvents
func (*ServerEvents) BlockMessage ¶
func (ce *ServerEvents) BlockMessage(msg Message, inbound bool)
Fires the "OnBlockMessage" event. The 'inbound' variables determines if the message is inbound or outgoing
func (*ServerEvents) Closed ¶
func (ce *ServerEvents) Closed(server CoapServer)
Fires the "OnClosed" event
func (*ServerEvents) Error ¶
func (ce *ServerEvents) Error(err error)
Fires the "OnError" event given an error object
func (*ServerEvents) Message ¶
func (ce *ServerEvents) Message(msg Message, inbound bool)
Fires the "OnMessage" event. The 'inbound' variables determines if the message is inbound or outgoing
func (*ServerEvents) Notify ¶
func (ce *ServerEvents) Notify(resource string, value interface{}, msg Message)
Fires the "OnNotify" event
func (*ServerEvents) Observe ¶
func (ce *ServerEvents) Observe(resource string, msg Message)
Fires the "OnObserve" event for a given resource
func (*ServerEvents) ObserveCancelled ¶
func (ce *ServerEvents) ObserveCancelled(resource string, msg Message)
Fires the "OnObserveCancelled" event for a given resource
func (*ServerEvents) OnBlockMessage ¶
func (ce *ServerEvents) OnBlockMessage(fn FnEventBlockMessage)
Fired when a block messageis received
func (*ServerEvents) OnClose ¶
func (ce *ServerEvents) OnClose(fn FnEventClose)
Fired when the server/client closes
func (*ServerEvents) OnDiscover ¶
func (ce *ServerEvents) OnDiscover(fn FnEventDiscover)
Fired when a discovery request is triggered
func (*ServerEvents) OnError ¶
func (ce *ServerEvents) OnError(fn FnEventError)
Catch-all event which is fired when an error occurs
func (*ServerEvents) OnMessage ¶
func (ce *ServerEvents) OnMessage(fn FnEventMessage)
Fired when a message is received
func (*ServerEvents) OnNotify ¶
func (ce *ServerEvents) OnNotify(fn FnEventNotify)
OnNotify is Fired when an observeed resource is notified
func (*ServerEvents) OnObserve ¶
func (ce *ServerEvents) OnObserve(fn FnEventObserve)
Fired when an observe request is triggered for a resource
func (*ServerEvents) OnObserveCancel ¶
func (ce *ServerEvents) OnObserveCancel(fn FnEventObserveCancel)
Fired when an observe-cancel request is triggered foa r esource
func (*ServerEvents) OnStart ¶
func (ce *ServerEvents) OnStart(fn FnEventStart)
Fired when the server/client starts up
func (*ServerEvents) Started ¶
func (ce *ServerEvents) Started(server CoapServer)
Fires the "OnStarted" event
type SortOptions ¶
type SortOptions []Option
type to sort the coap options list (which is mandatory) prior to transmission
func (SortOptions) Len ¶
func (opts SortOptions) Len() int
func (SortOptions) Less ¶
func (opts SortOptions) Less(i, j int) bool
func (SortOptions) Swap ¶
func (opts SortOptions) Swap(i, j int)
type UDPConnection ¶
type UDPConnection struct {
// contains filtered or unexported fields
}
func (*UDPConnection) CancelObserveResource ¶
func (c *UDPConnection) CancelObserveResource(resource string, token string) (err error)
func (*UDPConnection) Close ¶
func (c *UDPConnection) Close() error
func (*UDPConnection) Observe ¶
func (c *UDPConnection) Observe(ch chan ObserveMessage)
func (*UDPConnection) ObserveResource ¶
func (c *UDPConnection) ObserveResource(resource string) (tok string, err error)
func (*UDPConnection) SendMessage ¶
func (c *UDPConnection) SendMessage(msg Message) (resp Response, err error)
func (*UDPConnection) StopObserve ¶
func (c *UDPConnection) StopObserve(ch chan ObserveMessage)
type UDPServerConnection ¶
type UDPServerConnection struct {
// contains filtered or unexported fields
}
func (*UDPServerConnection) Close ¶
func (uc *UDPServerConnection) Close() error
func (*UDPServerConnection) LocalAddr ¶
func (uc *UDPServerConnection) LocalAddr() net.Addr
func (*UDPServerConnection) SetDeadline ¶
func (uc *UDPServerConnection) SetDeadline(t time.Time) error
func (*UDPServerConnection) SetReadDeadline ¶
func (uc *UDPServerConnection) SetReadDeadline(t time.Time) error
func (*UDPServerConnection) SetWriteDeadline ¶
func (uc *UDPServerConnection) SetWriteDeadline(t time.Time) error
type UDPServerSession ¶
type UDPServerSession struct {
// contains filtered or unexported fields
}
func (*UDPServerSession) GetAddress ¶
func (s *UDPServerSession) GetAddress() net.Addr
func (*UDPServerSession) GetConnection ¶
func (s *UDPServerSession) GetConnection() ServerConnection
func (*UDPServerSession) GetServer ¶
func (s *UDPServerSession) GetServer() CoapServer
func (*UDPServerSession) WriteBuffer ¶
func (s *UDPServerSession) WriteBuffer(b []byte) (n int)