rest

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractRESTRequest

func ExtractRESTRequest(c *Context, methods map[string]*Method) (*Request, *Response)

Types

type Context

type Context struct {
	HTTP    *http.Context
	Request *Request
}

func (*Context) Acknowledge

func (c *Context) Acknowledge() services.Response

func (*Context) Error

func (c *Context) Error(code int, message string, data interface{}) services.Response

func (*Context) InternalError

func (c *Context) InternalError() services.Response

func (*Context) InvalidParams

func (c *Context) InvalidParams(err error) services.Response

func (*Context) IsInternalError

func (c *Context) IsInternalError(resp services.Response) bool

func (*Context) MethodNotFound

func (c *Context) MethodNotFound() services.Response

func (*Context) Nil

func (c *Context) Nil() services.Response

func (*Context) NotFound

func (c *Context) NotFound() services.Response

func (*Context) Params

func (c *Context) Params() map[string]interface{}

func (*Context) Result

func (c *Context) Result(data interface{}) services.Response

type Error

type Error struct {
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type Handler

type Handler func(*Context) *Response

func MethodsHandler

func MethodsHandler(
	methods map[string]*Method,
	validateSettings *services.ValidateSettings) (Handler, error)

type Method

type Method struct {
	Form    *forms.Form
	Handler interface{}
	Path    string `json:"path"`
	Method  string `json:"method"`
	// contains filtered or unexported fields
}

func (*Method) Matches

func (m *Method) Matches(path, method string) (bool, map[string]interface{})

type RESTServer

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

func MakeRESTServer

func MakeRESTServer(settings *services.RESTServerSettings, handler Handler, metricsPrefix string, httpServer *http.HTTPServer) (*RESTServer, error)

func (*RESTServer) REST

func (s *RESTServer) REST(handler Handler) http.Handler

func (*RESTServer) Start

func (s *RESTServer) Start() error

func (*RESTServer) Stop

func (s *RESTServer) Stop() error

type Request

type Request struct {
	Method *Method                `json:"method"`
	Params map[string]interface{} `json:"params"`
}

type Response

type Response struct {
	StatusCode int         `json:"statusCode"`
	Data       interface{} `json:"result,omitempty"`
}

Jump to

Keyboard shortcuts

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