common

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IDSeparator is used for separation of IDs in the URL
	IDSeparator = ","
	// APIVersion defines the API version
	APIVersion = "0.3.0"
	// Default MIME type for all responses
	DefaultMIMEType = "application/vnd.eu.linksmart.hds+json;version=" + APIVersion

	// Location of APIs
	RegistryAPILoc = "/registry"
	DataAPILoc     = "/data"
	AggrAPILoc     = "/aggr"

	// Query parameters
	ParamPage    = "page"
	ParamPerPage = "per_page"
	ParamLimit   = "limit"
	ParamStart   = "start"
	ParamEnd     = "end"
	ParamSort    = "sort"
	// Values for ParamSort
	ASC  = "asc"  // ascending
	DESC = "desc" // descending
)
View Source
const (
	STRING = "string"
	FLOAT  = "float"
	BOOL   = "bool"
)

Data source types

Variables

This section is empty.

Functions

func ErrorResponse

func ErrorResponse(code int, msg string, w http.ResponseWriter)

ErrorResponse writes error to HTTP ResponseWriter

func ParsePagingParams

func ParsePagingParams(page, perPage string, maxPerPage int) (int, int, error)

func PerItemPagination

func PerItemPagination(_qLimit, _page, _perPage, _numOfSrcs int) ([]int, []int)

Calculate perItem and offset given the page, perPage, limit, and number of sources

func StartNotifier

func StartNotifier(in *chan Notification, out ...chan<- Notification)

Constructs notifier and starts multicasting

func Subscribers

func Subscribers() int

func SupportedAggregate

func SupportedAggregate(a string) bool

func SupportedInterval

func SupportedInterval(i string) bool

func SupportedType

func SupportedType(t string) bool

func ValidatePagingParams

func ValidatePagingParams(page, perPage, maxPerPage int) error

func ValidatePerItemLimit

func ValidatePerItemLimit(_qLimit, _perPage, _numOfSrcs int) error

Check if the parameters match the criteria required by PerItemPagination function

Types

type Error

type Error struct {
	// Code is the (http) code of the error
	Code int `json:"code"`
	// Message is the (human-readable) error message
	Message string `json:"message"`
}

Error describes an API error (serializable in JSON)

type Notification

type Notification struct {
	Type     NotificationType
	Payload  interface{}
	Callback chan error
}

A notification message

type NotificationType

type NotificationType uint8

Supported notification types

const (
	CREATE NotificationType = iota
	DELETE
	UPDATE
)

Jump to

Keyboard shortcuts

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