server

package
v0.0.0-...-3cdd1f1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: EUPL-1.2 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
const DefaultFromTime = -1 * time.Hour

DefaultFromTime contains the value for the 'from' parameter.

View Source
const DefaultMeasurementName = "cloudburst"

DefaultMeasurementName contains the measurement name when none is given in the request.

View Source
const DefaultToTime = 0 * time.Second

DefaultToTime contains the value for the 'to' parameter.

Variables

View Source
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 NewError

func NewError(code codes.Code, err error) *Error

NewError returns a new Error.

func NewErrorf

func NewErrorf(code codes.Code, format string, a ...interface{}) *Error

NewErrorf returns a new error with a custom description.

func (*Error) Error

func (e *Error) Error() string

Error returns the error text.

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"`
	PreSharedKey string `yaml:"psk"`
}

Listener represents the configuration for an HTTP/CoAP listener.

func (*Listener) ListAndServe

func (l *Listener) ListAndServe(s *Server) error

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        []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

func NewHTTPRequest(r *http.Request) *Request

NewHTTPRequest returns a Request based on an http.Request.

func (*Request) Measurement

func (r *Request) Measurement() (string, error)

Measurement returns the measurement name for the request.

func (*Request) PathHost

func (r *Request) PathHost() string

PathHost returns the `host` value in the request path.

func (*Request) QueryLast

func (r *Request) QueryLast() bool

QueryLast returns the `last` value in the query.

func (*Request) QueryTime

func (r *Request) QueryTime() (from, to time.Time, err error)

QueryTime returns the `from` and `to` (time) values in the query.

func (*Request) RequestHost

func (r *Request) RequestHost() (string, error)

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

func NewServer(influxClient *influxdb.Client) *Server

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.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(listeners ...*Listener) error

ListenAndServe starts handling requests based on the given listeners.

Jump to

Keyboard shortcuts

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