connect

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 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 ErrNotBinary = errors.New("received non-binary web socket message")

ErrNotBinary indicates that a non-binary websocket frame was received.

Functions

func Bridge

func Bridge(t *Transport, c *msg.Channel) error

Bridge will forward and return messages from the provided transport to the given channel.

func Handle

func Handle(handler func(*WebSocketConn)) http.Handler

Handle returns an HTTP handler that upgrades websocket requests and invokes handler.

func HandleFallback

func HandleFallback(fallback http.Handler, handler func(*WebSocketConn)) http.Handler

HandleFallback returns an HTTP handler that upgrades websocket requests and invokes handler.

func NewDevice

func NewDevice(url string, token string) msg.Device

NewDevice returns a msg.Device that connects through a Connect server.

Types

type Conn

type Conn interface {
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	SetReadDeadline(time.Time) error
	Read() ([]byte, error)
	Write([]byte) (int, error)
	Close() error
}

Conn exchanges packet-oriented binary messages over a connection.

type Description

type Description struct {
	UUID        string    `json:"uuid"`
	Connected   time.Time `json:"connected"`
	DeviceID    string    `json:"device_id,omitempty"`
	DeviceName  string    `json:"device_name,omitempty"`
	AppName     string    `json:"app_name,omitempty"`
	AppVersion  string    `json:"app_version,omitempty"`
	AttachURL   string    `json:"attach_url"`
	AttachToken string    `json:"attach_token,omitempty"`
}

Description describes a remotely connected device.

func List

func List(url string, token string) ([]Description, error)

List fetches the currently connected devices from a NAOS Connect server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements a NAOS Connect server.

func NewServer

func NewServer() *Server

NewServer returns a new NAOS Connect server.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the NAOS Connect HTTP and websocket endpoints.

func (*Server) SetLogger

func (s *Server) SetLogger(logger func(string, ...any))

SetLogger sets the server logger.

func (*Server) SetToken

func (s *Server) SetToken(token string)

SetToken sets the token required to access the server. If empty, access is unrestricted.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport adapts a connection to the msg.Transport interface.

func NewTransport

func NewTransport(conn Conn) *Transport

NewTransport wraps the provided connection in a raw transport.

func (*Transport) Close

func (t *Transport) Close()

func (*Transport) Read

func (t *Transport) Read() ([]byte, error)

func (*Transport) Write

func (t *Transport) Write(data []byte) error

type WebSocketConn

type WebSocketConn struct {
	// contains filtered or unexported fields
}

WebSocketConn adapts a Gorilla websocket connection to Conn.

func NewWebSocketConn

func NewWebSocketConn(conn *websocket.Conn) *WebSocketConn

NewWebSocketConn wraps a Gorilla websocket connection.

func (*WebSocketConn) Close

func (c *WebSocketConn) Close() error

Close closes the websocket connection.

func (*WebSocketConn) LocalAddr

func (c *WebSocketConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*WebSocketConn) Read

func (c *WebSocketConn) Read() ([]byte, error)

Read returns the next binary websocket message.

func (*WebSocketConn) RemoteAddr

func (c *WebSocketConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*WebSocketConn) SetReadDeadline

func (c *WebSocketConn) SetReadDeadline(t time.Time) error

SetReadDeadline forwards the read deadline to the websocket connection.

func (*WebSocketConn) Write

func (c *WebSocketConn) Write(buf []byte) (int, error)

Write sends a single binary websocket message.

type WebSocketUpgrader

type WebSocketUpgrader struct {
	// contains filtered or unexported fields
}

WebSocketUpgrader upgrades HTTP requests to the NAOS Connect websocket transport.

func NewWebSocketUpgrader

func NewWebSocketUpgrader(fallback http.Handler) *WebSocketUpgrader

NewWebSocketUpgrader returns a websocket upgrader with NAOS Connect defaults.

func (*WebSocketUpgrader) Upgrade

Upgrade upgrades a websocket request or forwards to the fallback handler.

Jump to

Keyboard shortcuts

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