Documentation
¶
Index ¶
- func AttachLocalhostClient(ctx context.Context, deviceExportMeta *usbip.ExportMeta, ...) error
- func CheckAutoAttachPrerequisites(_ bool, logger *slog.Logger) bool
- func ErrBadRequest(detail string) *apitypes.ApiError
- func ErrConflict(detail string) *apitypes.ApiError
- func ErrInternal(detail string) *apitypes.ApiError
- func ErrNotFound(detail string) *apitypes.ApiError
- func ListDeviceTypes() []string
- func RegisterDevice(name string, reg DeviceRegistration)
- func WrapError(err error) *apitypes.ApiError
- type DeviceRegistration
- type HandlerFunc
- type Request
- type Response
- type Router
- type Server
- type ServerConfig
- type StreamHandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttachLocalhostClient ¶
func CheckAutoAttachPrerequisites ¶
CheckAutoAttachPrerequisites checks if auto-attach prerequisites are met on Linux. Returns true if all requirements are satisfied, false otherwise with helpful log messages.
func ErrBadRequest ¶
Factory helpers returning *apitypes.ApiError (single canonical error type).
func ErrConflict ¶
func ErrInternal ¶
func ErrNotFound ¶
func ListDeviceTypes ¶ added in v0.3.2
func ListDeviceTypes() []string
ListDeviceTypes returns a list of all registered device type names.
func RegisterDevice ¶
func RegisterDevice(name string, reg DeviceRegistration)
RegisterDevice registers a device type for dynamic creation and handler dispatch. This should be called from device package init() functions. The name is case-insensitive and will be lowercased.
Types ¶
type DeviceRegistration ¶
type DeviceRegistration interface {
// CreateDevice returns a new device instance of this type.
CreateDevice(o *device.CreateOptions) usb.Device
// StreamHandler returns the handler function for long-lived connections.
StreamHandler() StreamHandlerFunc
}
DeviceRegistration describes a device type, providing both device creation and stream handler registration.
func GetRegistration ¶
func GetRegistration(name string) DeviceRegistration
GetRegistration retrieves a registered device handler by name for device creation. Returns nil if not found. Name lookup is case-insensitive.
type HandlerFunc ¶
HandlerFunc processes a request and populates the response. Returns an error on failure. The logger provided is a connection-scoped logger enriched with remote address metadata by the API server.
type Response ¶
type Response struct {
JSON string
}
Response holds the JSON string to return to the client.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router implements simple path pattern matching with placeholders in {name}.
func (*Router) Match ¶
func (r *Router) Match(path string) (HandlerFunc, map[string]string)
Match returns the HandlerFunc and params if the given path matches any registered pattern. Returns nil if none match.
func (*Router) MatchStream ¶
func (r *Router) MatchStream(path string) (StreamHandlerFunc, map[string]string)
MatchStream returns the StreamHandler and params if the given path matches any registered stream pattern. Returns nil if none match.
func (*Router) Register ¶
func (r *Router) Register(pattern string, handler HandlerFunc)
Register registers a handler for a path pattern like "bus/{id}/list".
func (*Router) RegisterStream ¶
func (r *Router) RegisterStream(pattern string, handler StreamHandlerFunc)
RegisterStream registers a StreamHandler for long-lived TCP connections.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements a small TCP API for managing virtual bus topology.
func (*Server) Addr ¶ added in v0.3.2
Addr returns the actual address the server is listening on. If Start hasn't been called yet, it returns the configured address.
func (*Server) Config ¶
func (a *Server) Config() ServerConfig
Config returns the server configuration.
func (*Server) Router ¶
Router returns the router used by the API server so callers can register handlers.
type ServerConfig ¶
type ServerConfig struct {
Addr string `help:"API server listen address" default:":3242" env:"VIIPER_API_ADDR"`
DeviceHandlerConnectTimeout time.Duration `` /* 136-byte string literal not displayed */
AutoAttachLocalClient bool `` /* 146-byte string literal not displayed */
ConnectionTimeout time.Duration `kong:"-"`
// contains filtered or unexported fields
}
ServerConfig represents the server subcommand configuration.
type StreamHandlerFunc ¶
StreamHandlerFunc handles long-lived TCP connections for bidirectional streaming. The handler takes ownership of the connection and should close it when done. The logger provided is connection-scoped. Returning a non-nil error indicates the handler encountered a terminal failure; the dispatcher/server will log it.
func DeviceStreamHandler ¶
func DeviceStreamHandler(srv *usb.Server) StreamHandlerFunc
DeviceStreamHandler returns a stream handler func that dynamically dispatches to device-specific handlers based on device type.
func GetStreamHandler ¶
func GetStreamHandler(name string) StreamHandlerFunc
GetStreamHandler retrieves the stream handler for a registered device type. Returns nil if not found. Name lookup is case-insensitive.