handler

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextKey

type ContextKey string
const (
	ContextUserKey ContextKey = "userID"
	NoResult                  = 0
)

type HandleRequest

type HandleRequest func(
	rw http.ResponseWriter,
	r *http.Request,
) models.RequestResult

HandleRequest handle request and return Result

type Handler

type Handler struct{}

func New

func New() *Handler

func (*Handler) Debug

func (h *Handler) Debug(
	catched error,
	number int,
	place string,
)

func (*Handler) Fail

func (h *Handler) Fail(
	code int,
	err error,
) models.RequestResult

func (*Handler) HandleFunc

func (h *Handler) HandleFunc(
	rf models.ResultFunc,
) func(http.ResponseWriter, *http.Request)

func (*Handler) ModelFromRequest

func (h *Handler) ModelFromRequest(
	r *http.Request,
	jt models.JSONtype,
) error

func (*Handler) OPTIONS

func (h *Handler) OPTIONS() func(
	rw http.ResponseWriter,
	r *http.Request,
) models.RequestResult

func (*Handler) Route

func (h *Handler) Route(
	rw http.ResponseWriter,
	r *http.Request,
	mHr MethodHandlers,
)

Route direct the request depending on its method mHr - map, where key - method, value - HandleRequest

func (*Handler) Send

func (h *Handler) Send(
	rw http.ResponseWriter,
	request *http.Request,
	result *models.RequestResult,
)

func (*Handler) SendError

func (h *Handler) SendError(code int, err error) func(
	rw http.ResponseWriter,
	r *http.Request,
) models.RequestResult

func (*Handler) SendResult

func (h *Handler) SendResult(
	rw http.ResponseWriter,
	result models.RequestResult,
)

SendResult send result to client

func (*Handler) Success

func (h *Handler) Success(
	code int,
	send models.JSONtype,
) models.RequestResult

func (*Handler) Warning

func (h *Handler) Warning(
	err error,
	text string,
)

type MethodHandlers

type MethodHandlers map[string]HandleRequest

MethodHandlers - map, where key - method, value - HandleRequest

Jump to

Keyboard shortcuts

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