api

package
v0.0.0-...-31e18c8 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2017 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleRequest

func HandleRequest(controller DestroyableController, rs Response) error

HandleRequest handle API request using Controller produced by ControllerFactory and sets response status to BadRequest with error message, if controller returns ValidationError

func SetRegisterer

func SetRegisterer(registerer Registerer)

Types

type Controller

type Controller interface {
	Run() error
}

Controller represents ability to call business logic from request handling method

type ControllerDestroyer

type ControllerDestroyer interface {
	Destroy() error
}

ControllerDestroyer function to be called when controller is no longer needed during request

type ControllerFactoryFunc

type ControllerFactoryFunc func(Request, Response) (Controller, ControllerDestroyer, error)

ControllerFactoryFunc function to be called when controller is no longer needed during request

type DestroyableController

type DestroyableController struct {
	C  Controller
	Cd ControllerDestroyer
}

DestroyableController wrapper to handle controller destruction after usage

func (DestroyableController) Destroy

func (d DestroyableController) Destroy() error

func (DestroyableController) Run

func (d DestroyableController) Run() error

type Handler

type Handler interface {
	Handle(Request, Response) error
}

type MessageResponse

type MessageResponse struct {
	Message string `json:"message"`
}

MessageResponse represents JSON message response body

func Message

func Message(err error) MessageResponse

Message returns new message response body, based on error message

type NullDestroyer

type NullDestroyer struct {
}

func (NullDestroyer) Destroy

func (NullDestroyer) Destroy() error

type NullRegisterer

type NullRegisterer struct {
}

func (NullRegisterer) DELETE

func (NullRegisterer) DELETE(prefix string, path string, handler Handler)

func (NullRegisterer) GET

func (NullRegisterer) GET(prefix string, path string, handler Handler)

func (NullRegisterer) PATCH

func (NullRegisterer) PATCH(prefix string, path string, handler Handler)

func (NullRegisterer) POST

func (NullRegisterer) POST(prefix string, path string, handler Handler)

func (NullRegisterer) PUT

func (NullRegisterer) PUT(prefix string, path string, handler Handler)

type Registerer

type Registerer interface {
	GET(prefix string, path string, handler Handler)
	PATCH(prefix string, path string, handler Handler)
	POST(prefix string, path string, handler Handler)
	PUT(prefix string, path string, handler Handler)
	DELETE(prefix string, path string, handler Handler)
}

Registerer represents ability to register methods in http API

func GetRegisterer

func GetRegisterer() Registerer

type Request

type Request interface {
	Param(name string) string
	Bind(i interface{}) error
}

Request represents ability to read request data

type Response

type Response interface {
	String(code int, s string) error
	JSON(code int, i interface{}) error
	NoContent(code int) error
}

Response represents ability to send response to user

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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