Documentation ¶
Index ¶
- Variables
- func IsRecursionRequest(r *http.Request) bool
- type API
- type Command
- type FileResponseEntry
- type MiddlewareFunc
- type Operation
- type Request
- type Response
- func AuthorizationError(err error) Response
- func BadRequest(err error) Response
- func FileResponse(r *http.Request, files []FileResponseEntry, headers map[string]string, ...) Response
- func ForwardedResponse(doer client.Doer, request *http.Request, path string) Response
- func InternalError(err error) Response
- func NotFoundError(what string) Response
- func OperationResponse(op *Operation) Response
- func PreconditionFailed(err error) Response
- func SmartError(err error) Response
- func SyncResponse(success bool, metadata interface{}) Response
- func SyncResponseETag(success bool, metadata interface{}, etag interface{}) Response
- func SyncResponseHeaders(success bool, metadata interface{}, headers map[string]string) Response
- func SyncResponseLocation(success bool, metadata interface{}, location string) Response
- func SyncResponseRedirect(address string) Response
- type Service
Constants ¶
This section is empty.
Variables ¶
var ( NotImplemented = &errorResponse{http.StatusNotImplemented, "not implemented"} NotFound = &errorResponse{http.StatusNotFound, "not found"} Forbidden = &errorResponse{http.StatusForbidden, "not authorized"} Conflict = &errorResponse{http.StatusConflict, "already exists"} )
Different error responses
var EmptySyncResponse = &syncResponse{success: true, metadata: make(map[string]interface{})}
EmptySyncResponse returns an empty synchronous response
Functions ¶
func IsRecursionRequest ¶
IsRecursionRequest checks whether the given HTTP request is marked with the "recursion" flag in its form values.
Types ¶
type API ¶
type API struct { Version string Middleware MiddlewareFunc Commands []*Command }
API holds all the commands and metadata for a specific version of the API
type Command ¶
type Command struct { Name string Middleware MiddlewareFunc GET handlerFunc PUT handlerFunc POST handlerFunc DELETE handlerFunc PATCH handlerFunc }
Command is the basic structure for every API call.
type FileResponseEntry ¶
type FileResponseEntry struct { Identifier string Path string Filename string Buffer []byte /* either a path or a buffer must be provided */ }
FileResponseEntry is a file transfer response
type MiddlewareFunc ¶
MiddlewareFunc describes a function uses to process a HTTP request as a middleman
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation struct holding metadata for an API operation, including handlers for run, cancel or socket connection; metadata, status or dates it was created, updated, etc..
func (*Operation) Render ¶
Render writes in response the operation details, included the list of resources (urls)
type Request ¶
Request represents the context of a REST request
func (*Request) CreateOperation ¶
func (r *Request) CreateOperation( description string, opResources map[string][]string, opMetadata interface{}, onRun func(*Operation) error, cancel context.CancelFunc) (*Operation, error)
CreateOperation creates an operation to be executed asynchronously
func (*Request) IsRecursionRequest ¶
IsRecursionRequest checks whether the given HTTP request is marked with the "recursion" flag in its form values.
type Response ¶
type Response interface { Render(w http.ResponseWriter) error String() string }
Response knows how to render itself
func AuthorizationError ¶
AuthorizationError returns a 401 http response renderer
func BadRequest ¶
BadRequest returns a 400 http response renderer
func FileResponse ¶
func FileResponse(r *http.Request, files []FileResponseEntry, headers map[string]string, removeAfterServe bool) Response
FileResponse returns a response renderer for a file download
func ForwardedResponse ¶
ForwardedResponse forwards a request to another endpoint and propagates back the response
func InternalError ¶
InternalError returns a 500 http response renderer
func NotFoundError ¶
NotFoundError returns a 404 http response renderer
func OperationResponse ¶
OperationResponse returns an http response renderer for an operation request
func PreconditionFailed ¶
PreconditionFailed returns a 412 http response renderer
func SmartError ¶
SmartError returns the right error message based on err.
func SyncResponse ¶
SyncResponse returns a synchronous http response renderer
func SyncResponseETag ¶
SyncResponseETag returns a synchronous http response renderer with a etag header value
func SyncResponseHeaders ¶
SyncResponseHeaders returns a synchronous response with custom headers
func SyncResponseLocation ¶
SyncResponseLocation returns a synchronous http response renderer with a location header
func SyncResponseRedirect ¶
SyncResponseRedirect returns a 3xx permanent redirect response
type Service ¶
type Service struct { UnixSocketPath string // Group to own the unix socket created to expose REST locally UnixSocketOwner string ServerCertPath string ServerKeyPath string CAPath string Router *mux.Router // Host where server listens. If empty, server listens in all host IPs Host string // Service port Port int // Dispatcher of jobs/workers to attend asynchronous requests MaxQueuedOperations int MaxConcurrentOperations int // contains filtered or unexported fields }
A Service can respond to http requests to the REST API
func (*Service) Init ¶
Init initializes REST service daemon by creating mux router if not created, populate router with defined array of APIs, open and setup database
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package endpoints is a generated GoMock package.
|
Package endpoints is a generated GoMock package. |
examples
|
|