rest

package
v0.0.0-...-3098c48 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2016 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package rest provides a framework for implementing a REST server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlankLineFilter

func BlankLineFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

BlankLineFilter adds a blank line at the end of each request.

func ForbiddenFilter

func ForbiddenFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

ForbiddenFilter blocks all requests.

func LogFilter

func LogFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

LogFilter enriches the log with requenst/response data.

func NewTokenAuthFilter

func NewTokenAuthFilter(token string) restful.FilterFunction

NewTokenAuthFilter only allows requests with the Header 'Authorization: "Bearer token"'.

func NoOpFilter

func NoOpFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

NoOpFilter is a simple No-Op filter for go-restful.

func ReadEntityOrBadRequest

func ReadEntityOrBadRequest(readTo interface{}, request *restful.Request, response *restful.Response) bool

ReadEntityOrBadRequest parses body of request into readTo and replies with a 400 error message on failure.

func RecoverFilter

func RecoverFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

RecoverFilter captures a panic and responds with an API Error.

func RegisterSwagger

func RegisterSwagger(s *Server)

RegisterSwagger exposes swagger definitions at /apidocs.json.

func RespondOrDie

func RespondOrDie(code int, entity interface{}, err error, response *restful.Response)

RespondOrDie is a convenience function for responding to a request. If given err is nil, this function writes the entity and code to the response. Otherwise err and its error code is written to the response. It panics on an unexpected error.

func WriteValidationError

func WriteValidationError(issueList api.IssueList, response *restful.Response)

WriteValidationError creates an UnprocessableEntity Error and writes to response.

Types

type HealthzResource

type HealthzResource struct{}

HealthzResource is a REST resource for reporting health status.

func NewHealthzResource

func NewHealthzResource() *HealthzResource

NewHealthzResource creates a new HealthzResource.

func (*HealthzResource) Register

func (r *HealthzResource) Register(s *Server)

Register adds Resource to the provided Server.

type Resource

type Resource interface {
	Register(s *Server)
}

Resource is the interface of a REST Resource.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a RESTful HTTP Server.

func NewServer

func NewServer() *Server

NewServer returns an empty REST Server.

func NewStandardServer

func NewStandardServer() *Server

NewStandardServer returns a preconfigured full-featured REST Server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the http handler.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(listen string) error

ListenAndServe starts the HTTP Server and blocks.

func (*Server) Register

func (s *Server) Register(ws *restful.WebService)

Register adds ws to the REST container.

Directories

Path Synopsis
Package resttest provides testing utilities for testing the rest package.
Package resttest provides testing utilities for testing the rest package.

Jump to

Keyboard shortcuts

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