Documentation ¶
Overview ¶
Package generichttp defines interfaces for generic devices and an extensible type that wraps them in an HTTP interface
Index ¶
- func GetBool(fcn func() (bool, error)) http.HandlerFunc
- func GetFloat(fcn func() (float64, error)) http.HandlerFunc
- func GetInt(fcn func() (int, error)) http.HandlerFunc
- func GetString(fcn func() (string, error)) http.HandlerFunc
- func SetBool(fcn func(bool) error) http.HandlerFunc
- func SetFloat(fcn func(float64) error) http.HandlerFunc
- func SetInt(fcn func(int) error) http.HandlerFunc
- func SetString(fcn func(string) error) http.HandlerFunc
- func SubMuxSanitize(str string) string
- type BoolT
- type BufferT
- type ByteT
- type FloatT
- type HTTPer
- type HumanPayload
- type IntT
- type MethodPath
- type RouteTable
- type StrT
- type Uint32T
- type UintT
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 ¶
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 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
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 |