common

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 2 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	// Bind is a helper function which binds the request body to a provided value to be parsed as JSON
	Bind(value interface{}) (err error)
	// Param will return the associated parameter value with the provided key
	Param(key string) (value string)
	// AddHook will append a new hook to the Context
	AddHook(hook Hook)

	// Get will retrieve a value for a provided key from the Context's internal storage
	Get(key string) (value string)
	// Put will set a value for a provided key into the Context's internal storage
	Put(key, value string)

	// WriteString will write as a string value
	WriteString(status int, contentType, str string) error
	// WriteBytes will write as a byteslice value
	WriteBytes(status int, contentType string, str []byte) error
	// WriteReader will write as a reader value
	WriteReader(status int, contentType string, r io.Reader) error
	// WriteJSON will write as JSON
	WriteJSON(status int, value interface{}) error
	// WriteNoContent will write a no content response
	WriteNoContent() error
	// Redirect will redirect the client
	Redirect(status int, destination string) error

	// Request will return the underlying http.Request
	Request() (req *http.Request)
	// Writer will return the underlying response writer.
	Writer() (writer http.ResponseWriter)
}

Context is the http context plugins need to support handlers

type Group added in v0.5.2

type Group interface {
	GET(route string, hs ...Handler)
	POST(route string, hs ...Handler)
	PUT(route string, hs ...Handler)
	DELETE(route string, hs ...Handler)
	OPTIONS(route string, hs ...Handler)

	Group(route string, hs ...Handler) Group
	Handle(method, route string, hs ...Handler)
}

Group is a grouping interface

type Handler

type Handler func(ctx Context)

Handler is the HTTP handler type

type Hook added in v0.1.6

type Hook func(statusCode int, ctx Context)

Hook is a function called after the response has been completed to the requester

type Plugins

type Plugins interface {
	Backend(key string, val interface{}) error
}

Plugins represents the plugins library interface. This allows for plugins and libraries to not be affected by vroomy/plugins version changes.

type Response

type Response struct {
	StatusCode  int
	ContentType string
	Value       interface{}

	// Optional fields used by a minority of responses
	Adopted  bool
	Callback string
}

Response determines how the server will respond

func NewAdopedtResponse added in v0.2.0

func NewAdopedtResponse() *Response

NewAdopedtResponse will return a new adopted Response

func NewResponse added in v0.2.0

func NewResponse(statusCode int, contentType string, value interface{}) *Response

NewResponse will return a new Response

Jump to

Keyboard shortcuts

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