client

package
v3.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenlessRequestsBlocked = errors.New("tokenless requests blocked after an unsuccessful request: a late response could be mistaken for a new response; recreate the connection to send tokenless requests again")

ErrTokenlessRequestsBlocked indicates that the connection must be recreated before sending another tokenless request.

Functions

func FormatUnknownCriticalOptionsDiagnostic added in v3.5.5

func FormatUnknownCriticalOptionsDiagnostic(unknownCriticalOpts []message.OptionID) string

func GetUnknownCriticalOptions added in v3.5.5

func GetUnknownCriticalOptions(options message.Options) []message.OptionID

GetUnknownCriticalOptions returns unique unknown critical option IDs in option-order. Known critical options with illegal value length are treated as unknown (RFC7252 section 5.4.3), as are repeated occurrences of a non-repeatable critical option (RFC7252 section 5.4.5).

func GetUnknownCriticalOptionsWithQBlock added in v3.7.0

func GetUnknownCriticalOptionsWithQBlock(options message.Options, enabled bool) []message.OptionID

GetUnknownCriticalOptionsWithQBlock permits Q options only when the caller has an active datagram Q-Block receiver. TCP and legacy callers reject them.

func RegisterRequestHandler added in v3.5.9

func RegisterRequestHandler[C responsewriter.Client](
	token message.Token,
	tokenHandlers *coapSync.Map[uint64, func(*responsewriter.ResponseWriter[C], *pool.Message)],
	tokenlessHandler *TokenlessHandler[func(*responsewriter.ResponseWriter[C], *pool.Message)],
) (<-chan *pool.Message, func(error) error, error)

RegisterRequestHandler registers a response handler and returns its response channel and cleanup function. Cleanup takes the request error and returns it with recovery instructions if tokenless requests become blocked. Errors marked RequestNotSentError leave tokenless requests usable.

Types

type Client

type Client[C Conn] struct {
	*limitparallelrequests.LimitParallelRequests
	// contains filtered or unexported fields
}

func New

func New[C Conn](cc C, observationHandler *observation.Handler[C], getToken GetTokenFunc, limitParallelRequests *limitparallelrequests.LimitParallelRequests) *Client[C]

func (*Client[C]) Delete

func (c *Client[C]) Delete(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)

Delete deletes the resource identified by the request path.

Use ctx to set timeout.

func (*Client[C]) Fetch added in v3.8.0

func (c *Client[C]) Fetch(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

Fetch issues a FETCH to the specified path.

Use ctx to set timeout.

func (*Client[C]) Get

func (c *Client[C]) Get(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)

Get issues a GET to the specified path.

Use ctx to set timeout.

An error is returned if by failure to speak COAP (such as a network connectivity problem). Any status code doesn't cause an error.

func (*Client[C]) GetObservationRequest

func (c *Client[C]) GetObservationRequest(token message.Token) (*pool.Message, bool)

func (*Client[C]) GetToken

func (c *Client[C]) GetToken() (message.Token, error)

func (*Client[C]) IPatch added in v3.8.0

func (c *Client[C]) IPatch(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

IPatch issues an iPATCH to the specified path.

Use ctx to set timeout.

func (*Client[C]) NewDeleteRequest

func (c *Client[C]) NewDeleteRequest(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)

NewDeleteRequest creates delete request.

Use ctx to set timeout.

func (*Client[C]) NewFetchRequest added in v3.8.0

func (c *Client[C]) NewFetchRequest(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

NewFetchRequest creates a FETCH request.

Use ctx to set timeout.

func (*Client[C]) NewGetRequest

func (c *Client[C]) NewGetRequest(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)

NewGetRequest creates get request.

Use ctx to set timeout.

func (*Client[C]) NewIPatchRequest added in v3.8.0

func (c *Client[C]) NewIPatchRequest(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

NewIPatchRequest creates an iPATCH request.

Use ctx to set timeout.

func (*Client[C]) NewObserveRequest

func (c *Client[C]) NewObserveRequest(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)

NewObserveRequest creates observe request.

Use ctx to set timeout.

func (*Client[C]) NewPatchRequest added in v3.8.0

func (c *Client[C]) NewPatchRequest(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

NewPatchRequest creates a PATCH request.

Use ctx to set timeout.

func (*Client[C]) NewPostRequest

func (c *Client[C]) NewPostRequest(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

NewPostRequest creates post request.

Use ctx to set timeout.

An error is returned if by failure to speak COAP (such as a network connectivity problem). Any status code doesn't cause an error.

If payload is nil then content format is not used.

func (*Client[C]) NewPutRequest

func (c *Client[C]) NewPutRequest(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

NewPutRequest creates put request.

Use ctx to set timeout.

If payload is nil then content format is not used.

func (*Client[C]) Observe

func (c *Client[C]) Observe(ctx context.Context, path string, observeFunc func(req *pool.Message), opts ...message.Option) (Observation, error)

Observe subscribes for every change of resource on path.

func (*Client[C]) Patch added in v3.8.0

func (c *Client[C]) Patch(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

Patch issues a PATCH to the specified path.

Use ctx to set timeout.

func (*Client[C]) Ping

func (c *Client[C]) Ping(ctx context.Context) error

Ping issues a PING to the client and waits for PONG response.

Use ctx to set timeout.

func (*Client[C]) Post

func (c *Client[C]) Post(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

Post issues a POST to the specified path.

Use ctx to set timeout.

An error is returned if by failure to speak COAP (such as a network connectivity problem). Any status code doesn't cause an error.

If payload is nil then content format is not used.

func (*Client[C]) Put

func (c *Client[C]) Put(ctx context.Context, path string, contentFormat message.MediaType, payload io.ReadSeeker, opts ...message.Option) (*pool.Message, error)

Put issues a PUT to the specified path.

Use ctx to set timeout.

An error is returned if by failure to speak COAP (such as a network connectivity problem). Any status code doesn't cause an error.

If payload is nil then content format is not used.

type Conn

type Conn interface {
	// create message from pool
	AcquireMessage(ctx context.Context) *pool.Message
	// return back the message to the pool for next use
	ReleaseMessage(m *pool.Message)
	WriteMessage(req *pool.Message) error
	AsyncPing(receivedPong func()) (func(), error)
	Context() context.Context
}

type GetTokenFunc

type GetTokenFunc = func() (message.Token, error)

type Observation

type Observation = interface {
	Cancel(ctx context.Context, opts ...message.Option) error
	Canceled() bool
}

type ReceivedMessageReader added in v3.1.0

type ReceivedMessageReader[C ReceivedMessageReaderClient] struct {
	// contains filtered or unexported fields
}

func NewReceivedMessageReader added in v3.1.0

func NewReceivedMessageReader[C ReceivedMessageReaderClient](cc C, queueSize int) *ReceivedMessageReader[C]

NewReceivedMessageReader creates a new ReceivedMessageReader[C] instance.

func (*ReceivedMessageReader[C]) C added in v3.1.0

func (r *ReceivedMessageReader[C]) C() chan<- *pool.Message

C returns the channel to push received messages to.

func (*ReceivedMessageReader[C]) TryToReplaceLoop added in v3.1.0

func (r *ReceivedMessageReader[C]) TryToReplaceLoop()

TryToReplaceLoop function attempts to replace the loop with a new one, but only if the loop is not currently reading messages. If the loop is reading messages, the function returns immediately. If the loop is not reading messages, the current loop is closed, and new loopDone and readingMessages channels and variables are created.

type ReceivedMessageReaderClient added in v3.1.0

type ReceivedMessageReaderClient interface {
	Done() <-chan struct{}
	ProcessReceivedMessage(req *pool.Message)
}

type RequestNotSentError added in v3.5.9

type RequestNotSentError struct {
	Err error
}

RequestNotSentError identifies a failure that occurred before transmission. Transport errors must not use this wrapper if the peer might have received any part of the request.

func (*RequestNotSentError) Error added in v3.5.9

func (e *RequestNotSentError) Error() string

func (*RequestNotSentError) Unwrap added in v3.5.9

func (e *RequestNotSentError) Unwrap() error

type TokenlessHandler added in v3.5.9

type TokenlessHandler[H any] struct {
	// contains filtered or unexported fields
}

TokenlessHandler tracks the single pending tokenless request on a connection. Its zero value is ready to use.

func (*TokenlessHandler[H]) Load added in v3.5.9

func (h *TokenlessHandler[H]) Load(remove bool) (H, bool)

Load returns the current handler, optionally consuming it. The registration remains reserved until cleanup determines whether the request completed.

func (*TokenlessHandler[H]) Register added in v3.5.9

func (h *TokenlessHandler[H]) Register(handler H) (func(bool), error)

Register installs a handler and returns its cleanup function. Cleanup must be called with true only if the request completed successfully; otherwise future registrations are permanently blocked.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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