Documentation ¶
Index ¶
- Constants
- Variables
- func Query(uriString string, onReceived func(resp *Message), ...) (err error)
- type COAPCode
- type COAPType
- type Conn
- type Handler
- type MediaType
- type Message
- func (m *Message) AddOption(opID OptionID, val interface{})
- func (m Message) IsConfirmable() bool
- func (m *Message) MarshalBinary() ([]byte, error)
- func (m Message) Option(o OptionID) interface{}
- func (m Message) Options(o OptionID) []interface{}
- func (m Message) Path() []string
- func (m Message) PathString() string
- func (m *Message) RemoveOption(opID OptionID)
- func (m *Message) SetOption(opID OptionID, val interface{})
- func (m *Message) SetPath(s []string)
- func (m *Message) SetPathString(s string)
- func (m *Message) UnmarshalBinary(data []byte) error
- type MsgBuilder
- func (m *MsgBuilder) Accept(value interface{}) *MsgBuilder
- func (m *MsgBuilder) AddOption(opID OptionID, val interface{})
- func (m *MsgBuilder) Code(c COAPCode) *MsgBuilder
- func (m *MsgBuilder) ContentFormat(value interface{}) *MsgBuilder
- func (m *MsgBuilder) ETag(value interface{}) *MsgBuilder
- func (m *MsgBuilder) IfMatch(value interface{}) *MsgBuilder
- func (m *MsgBuilder) IfNoneMatch(value interface{}) *MsgBuilder
- func (m *MsgBuilder) LocationQuery(value interface{}) *MsgBuilder
- func (m *MsgBuilder) MaxAge(value interface{}) *MsgBuilder
- func (m *MsgBuilder) NewMessageID() uint16
- func (m *MsgBuilder) Observe(value interface{}) *MsgBuilder
- func (m *MsgBuilder) Option(o OptionID) interface{}
- func (m *MsgBuilder) Options(o OptionID) []interface{}
- func (m *MsgBuilder) ProxyScheme(value interface{}) *MsgBuilder
- func (m *MsgBuilder) ProxyURI(value interface{}) *MsgBuilder
- func (m *MsgBuilder) RemoveOption(opID OptionID) *MsgBuilder
- func (m *MsgBuilder) SetOption(opID OptionID, val interface{}) *MsgBuilder
- func (m *MsgBuilder) SetPath(s []string)
- func (m *MsgBuilder) SetPathString(s string)
- func (m *MsgBuilder) Size1(value interface{}) *MsgBuilder
- func (m *MsgBuilder) ToMessage() *Message
- func (m *MsgBuilder) Type(t COAPType) *MsgBuilder
- func (m *MsgBuilder) URIHost(value interface{}) *MsgBuilder
- func (m *MsgBuilder) URIPath(value interface{}) *MsgBuilder
- func (m *MsgBuilder) URIPort(value interface{}) *MsgBuilder
- func (m *MsgBuilder) URIQuery(value interface{}) *MsgBuilder
- type Opt
- type OptionID
- type PlainAuth
- type SerialNo
- type ServeMux
- type Server
- type TcpMessage
- type Transmitter
- type URI
Constants ¶
const ( // ResponseRandomFactor is a multiplier for response backoff. ResponseRandomFactor = 1.5 // MaxRetransmit is the maximum number of times a message will // be retransmitted. MaxRetransmit = 4 )
const ResponseTimeout = time.Second * 8
ResponseTimeout is the amount of time to wait for a response.
Variables ¶
var ( ErrInvalidTokenLen = errors.New("invalid token length") ErrOptionTooLong = errors.New("option is too long") ErrOptionGapTooLarge = errors.New("option gap too large") )
Message encoding errors.
Functions ¶
Types ¶
type COAPCode ¶
type COAPCode uint8
COAPCode is the type used for both request and response codes.
const ( Created COAPCode = 65 Deleted COAPCode = 66 Valid COAPCode = 67 Changed COAPCode = 68 Content COAPCode = 69 BadRequest COAPCode = 128 BadOption COAPCode = 130 Forbidden COAPCode = 131 NotFound COAPCode = 132 MethodNotAllowed COAPCode = 133 NotAcceptable COAPCode = 134 PreconditionFailed COAPCode = 140 RequestEntityTooLarge COAPCode = 141 UnsupportedMediaType COAPCode = 143 InternalServerError COAPCode = 160 NotImplemented COAPCode = 161 BadGateway COAPCode = 162 GatewayTimeout COAPCode = 164 ProxyingNotSupported COAPCode = 165 )
Response Codes
type COAPType ¶
type COAPType uint8
COAPType represents the message type.
const ( // Confirmable messages require acknowledgements. Confirmable COAPType = 0 // NonConfirmable messages do not require acknowledgements. NonConfirmable COAPType = 1 // Acknowledgement is a message indicating a response to confirmable message. Acknowledgement COAPType = 2 // Reset indicates a permanent negative acknowledgement. Reset COAPType = 3 )
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a CoAP client connection.
type Handler ¶
type Handler interface { // Handle the message and optionally return a response message. ServeCOAP(transmitter Transmitter, listener *net.UDPConn, addr *net.UDPAddr, m *Message) *Message }
Handler is a type that handles CoAP messages.
func FuncHandler ¶
func FuncHandler(f func(transmitter Transmitter, listener *net.UDPConn, addr *net.UDPAddr, m *Message) *Message) Handler
FuncHandler builds a handler from a function.
type MediaType ¶
type MediaType uint16
MediaType specifies the content type of a message.
const ( TextPlain MediaType = 0 // text/plain;charset=utf-8 AppLinkFormat MediaType = 40 // application/link-format AppXML MediaType = 41 // application/xml AppOctets MediaType = 42 // application/octet-stream AppExi MediaType = 47 // application/exi AppJSON MediaType = 50 // application/json )
Content types.
type Message ¶
type Message struct { Type COAPType Code COAPCode MessageID uint16 Token, Payload []byte // contains filtered or unexported fields }
Message is a CoAP message.
func ParseMessage ¶
ParseMessage extracts the Message from the given input.
func (Message) IsConfirmable ¶
IsConfirmable returns true if this message is confirmable.
func (*Message) MarshalBinary ¶
MarshalBinary produces the binary form of this Message.
func (Message) PathString ¶
PathString gets a path as a / separated string.
func (*Message) RemoveOption ¶
RemoveOption removes all references to an option
func (*Message) SetPathString ¶
SetPathString sets a path by a / separated string.
func (*Message) UnmarshalBinary ¶
UnmarshalBinary parses the given binary slice as a Message.
type MsgBuilder ¶
type MsgBuilder struct {
// contains filtered or unexported fields
}
func NewMsgBuilder ¶
func NewMsgBuilder(pathString string) *MsgBuilder
func (*MsgBuilder) Accept ¶
func (m *MsgBuilder) Accept(value interface{}) *MsgBuilder
func (*MsgBuilder) AddOption ¶
func (m *MsgBuilder) AddOption(opID OptionID, val interface{})
AddOption adds an option.
func (*MsgBuilder) Code ¶
func (m *MsgBuilder) Code(c COAPCode) *MsgBuilder
func (*MsgBuilder) ContentFormat ¶
func (m *MsgBuilder) ContentFormat(value interface{}) *MsgBuilder
func (*MsgBuilder) ETag ¶
func (m *MsgBuilder) ETag(value interface{}) *MsgBuilder
func (*MsgBuilder) IfMatch ¶
func (m *MsgBuilder) IfMatch(value interface{}) *MsgBuilder
func (*MsgBuilder) IfNoneMatch ¶
func (m *MsgBuilder) IfNoneMatch(value interface{}) *MsgBuilder
func (*MsgBuilder) LocationQuery ¶
func (m *MsgBuilder) LocationQuery(value interface{}) *MsgBuilder
func (*MsgBuilder) MaxAge ¶
func (m *MsgBuilder) MaxAge(value interface{}) *MsgBuilder
func (*MsgBuilder) NewMessageID ¶
func (m *MsgBuilder) NewMessageID() uint16
func (*MsgBuilder) Observe ¶
func (m *MsgBuilder) Observe(value interface{}) *MsgBuilder
func (*MsgBuilder) Option ¶
func (m *MsgBuilder) Option(o OptionID) interface{}
Option gets the first value for the given option ID.
func (*MsgBuilder) Options ¶
func (m *MsgBuilder) Options(o OptionID) []interface{}
Options gets all the values for the given option.
func (*MsgBuilder) ProxyScheme ¶
func (m *MsgBuilder) ProxyScheme(value interface{}) *MsgBuilder
func (*MsgBuilder) ProxyURI ¶
func (m *MsgBuilder) ProxyURI(value interface{}) *MsgBuilder
func (*MsgBuilder) RemoveOption ¶
func (m *MsgBuilder) RemoveOption(opID OptionID) *MsgBuilder
RemoveOption removes all references to an option
func (*MsgBuilder) SetOption ¶
func (m *MsgBuilder) SetOption(opID OptionID, val interface{}) *MsgBuilder
SetOption sets an option, discarding any previous value
func (*MsgBuilder) SetPath ¶
func (m *MsgBuilder) SetPath(s []string)
SetPath updates or adds a URIPath attribute on this message.
func (*MsgBuilder) SetPathString ¶
func (m *MsgBuilder) SetPathString(s string)
SetPathString sets a path by a / separated string.
func (*MsgBuilder) Size1 ¶
func (m *MsgBuilder) Size1(value interface{}) *MsgBuilder
func (*MsgBuilder) ToMessage ¶
func (m *MsgBuilder) ToMessage() *Message
func (*MsgBuilder) Type ¶
func (m *MsgBuilder) Type(t COAPType) *MsgBuilder
func (*MsgBuilder) URIHost ¶
func (m *MsgBuilder) URIHost(value interface{}) *MsgBuilder
func (*MsgBuilder) URIPath ¶
func (m *MsgBuilder) URIPath(value interface{}) *MsgBuilder
func (*MsgBuilder) URIPort ¶
func (m *MsgBuilder) URIPort(value interface{}) *MsgBuilder
func (*MsgBuilder) URIQuery ¶
func (m *MsgBuilder) URIQuery(value interface{}) *MsgBuilder
type OptionID ¶
type OptionID uint8
OptionID identifies an option in a message.
const ( IfMatch OptionID = 1 URIHost OptionID = 3 ETag OptionID = 4 IfNoneMatch OptionID = 5 Observe OptionID = 6 URIPort OptionID = 7 LocationPath OptionID = 8 URIPath OptionID = 11 ContentFormat OptionID = 12 MaxAge OptionID = 14 URIQuery OptionID = 15 Accept OptionID = 17 LocationQuery OptionID = 20 ProxyURI OptionID = 35 ProxyScheme OptionID = 39 Size1 OptionID = 60 )
Option IDs.
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux provides mappings from a common endpoint to handlers by request path.
type Server ¶
type Server struct { CmdrTlsConfig *tls.CmdrTLSConfig // contains filtered or unexported fields }
func (*Server) Close ¶
Close clean the internal resource, close the connections. After the server shutdown gracefully, server will Close() itself.
func (*Server) Serve ¶
Serve processes incoming UDP packets on the given listener, and processes these requests forever (or until the listener is closed).
type TcpMessage ¶
type TcpMessage struct {
Message
}
TcpMessage is a CoAP Message that can encode itself for TCP transport.
func Decode ¶
func Decode(r io.Reader) (*TcpMessage, error)
Decode reads a single message from its input.
func (*TcpMessage) MarshalBinary ¶
func (m *TcpMessage) MarshalBinary() ([]byte, error)
func (*TcpMessage) UnmarshalBinary ¶
func (m *TcpMessage) UnmarshalBinary(data []byte) error
type Transmitter ¶
type URI ¶
type URI struct { Scheme string Host string Port int Username string Password string Path string RawPath string }
URI represents a parsed AMQP URI string.
func ParseURI ¶
ParseURI attempts to parse the given CoAP URI according to the spec. See RFC-7252.
Default values for the fields are:
Scheme: coap Host: localhost Port: 5683 Username: guest Password: guest Path: /temp/txt