Documentation ¶
Index ¶
- Constants
- Variables
- 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 = "*/*" 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.
DefaultFromTime contains the value for the 'from' parameter.
const DefaultMeasurementName = "cloudburst"
DefaultMeasurementName contains the measurement name when none is given in the request.
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 CoAPResponseWriter ¶
type CoAPResponseWriter struct {
coap.ResponseWriter
}
CoAPResponseWriter is a CoAP based ResponseWriter.
func (*CoAPResponseWriter) SetContentType ¶
func (r *CoAPResponseWriter) SetContentType(t string)
SetContentType sets the content type using a given MIME type.
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 NewErrorf ¶
NewErrorf returns a new error with a custom description.
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) SetCode ¶
func (r *HTTPResponseWriter) SetCode(c codes.Code)
SetCode sets the response code.
func (*HTTPResponseWriter) SetContentType ¶
func (r *HTTPResponseWriter) SetContentType(t string)
SetContentType sets the content type using a given MIME type.
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.
type Request ¶
type Request struct { Method string RemoteAddr string Path []string Query url.Values ContentType string Accept string Body []byte }
Request represents a generic API request.
func NewCoAPRequest ¶
func NewCoAPRequest(r *coap.Request) *Request
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) PathHost ¶
PathHost returns the `host` value in the request path.
func (*Request) QueryLast ¶
QueryLast returns the `last` value in the query.
func (*Request) QueryTime ¶
QueryTime returns the `from` and `to` (time) values in the query.
func (*Request) RequestHost ¶
RequestHost returns the `host` for this request from either the path, or the remote address.
func (*Request) SenML ¶
func (r *Request) SenML() (measurements []senml.Measurement, err error)
SenML returns the SenML data encoded in the body.
type ResponseWriter ¶
type ResponseWriter interface { io.Writer // SetCode sets the response code. SetCode(codes.Code) // SetContentType sets the content type using a given MIME type. SetContentType(t string) // WriteErrors returns true if errors should be written to the client. WriteErrors() bool }
ResponseWriter is a generic response writer.
func NewCoAPResponseWriter ¶
func NewCoAPResponseWriter(w coap.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 coap.ResponseWriter, r *coap.Request)
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.