restcore

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *

* Copyright (c) 2016 The ConnectorDB Contributors Licensed under the MIT license. *

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrInvalidName is thrown when the name is bad
	ErrInvalidName = errors.New("The given name did not pass sanitation.")
	ErrBadQ        = errors.New("Unrecognized query command.")
	ErrCantParse   = errors.New("The given query cannot be parsed, since the values could not be extracted")
)

Functions

func Authenticator

func Authenticator(apifunc webcore.APIHandler, db *connectordb.Database) http.HandlerFunc

Authenticator runs authentication on a request, making sure that the REST API can handle it

func BadQ

func BadQ(o *authoperator.AuthOperator, writer http.ResponseWriter, request *http.Request, logger *log.Entry) error

BadQ checks if there is a q= part to the given query, and gives an error if there is

func GetStreamPath

func GetStreamPath(request *http.Request) (username string, devicename string, streamname string, streampath string)

GetStreamPath returns the relevant parts of a stream path

func IntWriter

func IntWriter(writer http.ResponseWriter, i int64, logger *log.Entry, err error) (int, string)

IntWriter writes an integer

func JSONWriter

func JSONWriter(writer http.ResponseWriter, data interface{}, logger *log.Entry, err error) (int, string)

JSONWriter writes the given data as http

func OK

func OK(writer http.ResponseWriter) error

OK is a simplifying function that returns success

func ParseIRange

func ParseIRange(q url.Values) (int64, int64, error)

ParseIRange attempts to parse a request as an index range

func ParseTRange

func ParseTRange(q url.Values) (float64, float64, int64, error)

ParseTRange attempts to parse a request parameters as time range

func UintWriter

func UintWriter(writer http.ResponseWriter, i uint64, logger *log.Entry, err error) (int, string)

UintWriter writes an unsigned integer

func UnmarshalRequest

func UnmarshalRequest(request *http.Request, unmarshalTo interface{}) error

UnmarshalRequest unmarshals the input data to the given interface

func ValidName

func ValidName(n string, err error) error

ValidName sanitizes names so that only valid ones are added

func WriteError

func WriteError(writer http.ResponseWriter, logger *log.Entry, errorCode int, err error, iserr bool) (int, string)

WriteError takes care of gracefully writing errors to the client in a way that allows for fairly easy debugging.

func WriteJSONResult

func WriteJSONResult(writer http.ResponseWriter, dr datastream.DataRange, logger *log.Entry, err error) (int, string)

WriteJSONResult writes a DataRange as a response

Types

type ErrorResponse

type ErrorResponse struct {
	Code      int    `json:"code"`
	Message   string `json:"msg"`
	Reference string `json:"ref,omitempty"`
}

ErrorResponse is the struct which holds the error message and response code

Jump to

Keyboard shortcuts

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