rest

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Alert should be corrected immediately e.g. Loss of the primary ISP connection.
	Alert = "alert"

	// Critical conditions e.g. A failure in the system's primary application.
	Critical = "crit"

	// Error conditions e.g. An application has exceeded its file storage limit and attempts to write are failing.
	Error = "err"

	// Warning may indicate that an error will occur if action is not taken. e.g. A non-root file system has only 2GB remaining.
	Warning = "warn"

	// Notice events that are unusual, but not error conditions. e.g. Ski Haus Delta reports temperature < low_notice(50)
	Notice = "notice"

	// Informational normal operational messages that require no action. e.g. An application has started, paused or ended successfully.
	Informational = "info"

	// Debug information useful to developers for debugging the application.
	Debug = "debug"
)

Syslog model error severity levels https://en.wikipedia.org/wiki/Syslog#Severity_level

Variables

This section is empty.

Functions

func ConfigureSwagger

func ConfigureSwagger(apiDocPath string, container *restful.Container)

ConfigureSwagger configures the swagger documentation for all endpoints in the container

func NewHTTPHandler

func NewHTTPHandler() *restful.Container

NewHTTPHandler returns a new restful container

func NewPath

func NewPath(root, doc string) *restful.WebService

NewPath returns a new API Path lie /api/something

func ParseRequestBody

func ParseRequestBody(r *restful.Request, o interface{}) error

ParseRequestBody parses request body

func UnsecuredHandler

func UnsecuredHandler(handler EndpointFunction) restful.RouteFunction

UnsecuredHandler is a handler for an open to the world endpoint

Types

type Container

type Container interface {
	Add(service *restful.WebService) *restful.Container
	RegisteredWebServices() []*restful.WebService
}

Container interfaces *restful.Container, a web service container

type EndpointFunction

type EndpointFunction func(*EndpointHandlerParams)

EndpointFunction is a function that intakes EndpointHandlerParams to respond to a RESTful call

type EndpointHandlerParams

type EndpointHandlerParams struct {
	Req  *restful.Request
	Resp *restful.Response
}

EndpointHandlerParams is a value passed to every function that is supposed to handle RESTful calls

type Resp

type Resp struct {
	Links struct {
		Self string `json:"self"`
	} `json:"links"`
	Metadata struct {
		Generated string `json:"generated"`
	} `json:"metadata"`
	Errors []RespError `json:"errors"`
}

Resp is the structure that will be in every API response

func (*Resp) AddDetailedError

func (r *Resp) AddDetailedError(restError RespError, format string, a ...interface{})

AddDetailedError adds a formatted REST error to response

func (*Resp) AddError

func (r *Resp) AddError(restError RespError)

AddError adds a REST error to response

func (*Resp) DecorateResponse

func (r *Resp) DecorateResponse(request *restful.Request)

DecorateResponse is executed before a response is generated

type RespError

type RespError struct {
	Severity             string `json:"severity"`
	HumanFriendlyMessage string `json:"human_friendly_message"`
	ShortMessage         string `json:"short_message"`
	Details              string `json:"details"`
}

RespError is an error that is part of the API response

Jump to

Keyboard shortcuts

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