Documentation ¶
Index ¶
- Constants
- Variables
- type Backend
- type CoAPResponseWriter
- type Error
- type HTTPResponseWriter
- type Listener
- type Request
- func (r *Request) Measurement() (string, error)
- func (r *Request) PathHost() string
- func (r *Request) QueryLast() bool
- func (r *Request) QueryTime() (from, to time.Time, err error)
- func (r *Request) RequestHost() (string, error)
- func (r *Request) SenML() (measurements []senml.Measurement, err error)
- type ResponseWriter
- type Server
Constants ¶
const ( TypeAny = "*/*" TypePlainText = "text/plain" TypeApplication = "application/*" TypeCBOR = "application/cbor" TypeJSON = "application/json" TypeXML = "application/xml" TypeSenMLCBOR = "application/senml+cbor" TypeSenMLJSON = "application/senml+json" TypeSenMLXML = "application/senml+xml" )
Supported MIME types.
const DefaultFromTime = -1 * time.Hour
DefaultFromTime contains the value for the 'from' parameter.
const DefaultMeasurementName = "cloudburst"
DefaultMeasurementName contains the measurement name when none is given in the request.
const DefaultToTime = 0 * time.Second
DefaultToTime contains the value for the 'to' parameter.
Variables ¶
var MeasurementNameRegex = regexp.MustCompile(`^\w+$`)
MeasurementNameRegex contains the regular expression used for validating measurements.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface { // Query retrieves SenML data from the backend with the given parameters. Query(name, host string, from, to time.Time, last bool) (measurements []senml.Measurement, err error) // Write writes SenML data to the backend. Write(name, host string, data ...senml.Measurement) error // Close closes the connection to the backend. Close() error }
Backend represents a backend for the Cloudburst server.
type CoAPResponseWriter ¶
type CoAPResponseWriter struct {
mux.ResponseWriter
}
CoAPResponseWriter is a CoAP based ResponseWriter.
func (*CoAPResponseWriter) SetResponse ¶
SetResponse sets the response code, content type and data
func (*CoAPResponseWriter) WriteErrors ¶
func (r *CoAPResponseWriter) WriteErrors() bool
WriteErrors returns true if errors should be written to the client.
type Error ¶
type Error struct { // The error causing this error. Err error // The corresponding response code. Code codes.Code }
Error is a generic request/response error.
func (*Error) Write ¶
func (e *Error) Write(w ResponseWriter, req *Request)
Write writes the for a Request to a ResponseWriter.
type HTTPResponseWriter ¶
type HTTPResponseWriter struct {
http.ResponseWriter
}
HTTPResponseWriter contains an HTTP based ResponseWriter.
func (*HTTPResponseWriter) SetResponse ¶
SetResponse sets the response code, content type and data
func (*HTTPResponseWriter) WriteErrors ¶
func (r *HTTPResponseWriter) WriteErrors() bool
WriteErrors returns true if errors should be written to the client.
type Listener ¶
type Listener struct { Type string `yaml:"type"` Address string `yaml:"address"` CertFile string `yaml:"tls_cert"` KeyFile string `yaml:"tls_key"` }
Listener represents the configuration for an HTTP/CoAP listener.
func (*Listener) ListAndServe ¶
ListAndServe starts a Listener for a Server.
type Request ¶
type Request struct { Method string RemoteAddr string Path []string Query url.Values ContentType string Accept string Body io.Reader Confirmable bool }
Request represents a generic API request.
func NewCoAPRequest ¶
NewCoAPRequest creates Request based on a coap.Request.
func NewHTTPRequest ¶
NewHTTPRequest returns a Request based on an http.Request.
func (*Request) Measurement ¶
Measurement returns the measurement name for the request.
func (*Request) RequestHost ¶
RequestHost returns the `host` for this request from either the path, or the remote address.
type ResponseWriter ¶
type ResponseWriter interface { // SetResponse sets the response code, content type and data. SetResponse(code codes.Code, contentType string, data []byte) error // WriteErrors returns true if errors should be written to the client. WriteErrors() bool }
ResponseWriter is a generic response writer.
func NewCoAPResponseWriter ¶
func NewCoAPResponseWriter(w mux.ResponseWriter) ResponseWriter
NewCoAPResponseWriter creates a CoAP based ResponseWriter.
func NewHTTPResponseWriter ¶
func NewHTTPResponseWriter(w http.ResponseWriter) ResponseWriter
NewHTTPResponseWriter returns ResponseWriter based on a http.ResponseWriter.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents a Cloudburst server.
func NewServer ¶
NewServer creates a server backed by a certain InfluxDB client and set of listeners.
func (*Server) CoAPHandler ¶
func (s *Server) CoAPHandler(w mux.ResponseWriter, r *mux.Message)
CoAPHandler handles CoAP requests.
func (*Server) HTTPHandler ¶
func (s *Server) HTTPHandler(w http.ResponseWriter, r *http.Request)
HTTPHandler handles HTTP requests.
func (*Server) Handler ¶
func (s *Server) Handler(w ResponseWriter, req *Request)
Handler handles generic API requests.
func (*Server) ListenAndServe ¶
ListenAndServe starts handling requests based on the given listeners.