generichttp

package
v0.0.0-...-efe4ef5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package generichttp defines interfaces for generic devices and an extensible type that wraps them in an HTTP interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool

func GetBool(fcn func() (bool, error)) http.HandlerFunc

GetBool calls a bool-getting function and returns the response as json {'bool': value}

func GetFloat

func GetFloat(fcn func() (float64, error)) http.HandlerFunc

GetFloat calls a float-getting function and returns the response as json {'f64': value}

func GetInt

func GetInt(fcn func() (int, error)) http.HandlerFunc

GetInt calls an int-getting function and returns the response as json {'int': value}

func GetString

func GetString(fcn func() (string, error)) http.HandlerFunc

GetString calls a string-getting function and returns the response as json {'str': value}

func SetBool

func SetBool(fcn func(bool) error) http.HandlerFunc

SetBool parses a JSON input of {'bool': value} and calls fcn with it

func SetFloat

func SetFloat(fcn func(float64) error) http.HandlerFunc

SetFloat parses a JSON input of {'f64': value} and calls fcn with it

func SetInt

func SetInt(fcn func(int) error) http.HandlerFunc

SetInt parses a JSON input of {'int': value} and calls fcn with it

func SetString

func SetString(fcn func(string) error) http.HandlerFunc

SetString parses a JSON input of {'int': value} and calls fcn with it

func SubMuxSanitize

func SubMuxSanitize(str string) string

SubMuxSanitize takes any string and ensures it begins with / and ends with /*

Types

type BoolT

type BoolT struct {
	Bool bool `json:"bool"`
}

BoolT is a sutrct with a single Bool field

type BufferT

type BufferT struct {
	Int []byte `json:"int"`
}

BufferT is a struct with a single Int field

type ByteT

type ByteT struct {
	Int byte `json:"int"` // we won't distinguish between bytes and ints for users
}

ByteT is a struct with a single Int field

type FloatT

type FloatT struct {
	F64 float64 `json:"f64"`
}

FloatT is a struct with a single F64 field

type HTTPer

type HTTPer interface {
	RT() RouteTable
}

HTTPer is an interface which allows types to yield their route tables for processing

type HumanPayload

type HumanPayload struct {
	// Bool holds a binary value
	Bool bool

	// Buffer holds raw bytes
	Buffer []byte

	// Byte holds a single byte
	Byte byte

	// Int holds an int
	Int int

	// Float holds a float
	Float float64

	// String holds a string
	String string

	// Uint16 holds a uint16
	Uint16 uint16

	// T holds the type of data actually contained in the payload
	T types.BasicKind
}

HumanPayload is a struct containing the basic types NKT devices may work with

func (*HumanPayload) EncodeAndRespond

func (hp *HumanPayload) EncodeAndRespond(w http.ResponseWriter, r *http.Request)

EncodeAndRespond converts the humanpayload to a smaller struct with only one field and writes it to w as JSON.

type IntT

type IntT struct {
	Int int `json:"int"`
}

IntT is a struct with a single Int field

type MethodPath

type MethodPath struct {
	Method, Path string
}

MethodPath is a path and method

type RouteTable

type RouteTable map[MethodPath]http.HandlerFunc

RouteTable maps methods and paths to handlers

func (RouteTable) Bind

func (rt RouteTable) Bind(r chi.Router)

Bind calls HandleFunc for each route in the table on the given mux. It also binds the endpoints route if it is not in the table already

func (RouteTable) Endpoints

func (rt RouteTable) Endpoints() []string

Endpoints returns the endpoints in the route table

func (RouteTable) EndpointsHTTP

func (rt RouteTable) EndpointsHTTP() func(http.ResponseWriter, *http.Request)

EndpointsHTTP returns a function that encodes the endpoint list to a ResponseWriter

type StrT

type StrT struct {
	Str string `json:"str"`
}

StrT is a struct with a single Str field

type Uint32T

type Uint32T struct {
	Uint uint32 `json:"uint"`
}

Uint32T is a struct with a single int field. It almost looks like IntT

type UintT

type UintT struct {
	Int uint16 `json:"int"`
}

UintT is a struct with a single Int field

Directories

Path Synopsis
Package ascii contains some injectable HTTP interfaces to ASCII hardware
Package ascii contains some injectable HTTP interfaces to ASCII hardware
Package camera provides a generic HTTP interface to a scientific camera
Package camera provides a generic HTTP interface to a scientific camera
Package daq provides a generic HTTP interface to ADC and DAC devices
Package daq provides a generic HTTP interface to ADC and DAC devices
Package laser exposes control of laser controllers over HTTP
Package laser exposes control of laser controllers over HTTP
Package motion provides an HTTP interface to motion controllers
Package motion provides an HTTP interface to motion controllers
Package thermal exposes an HTTP interface to thermal controllers
Package thermal exposes an HTTP interface to thermal controllers
Package tmc provides an HTTP interface to test and measurement devices
Package tmc provides an HTTP interface to test and measurement devices

Jump to

Keyboard shortcuts

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