router

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: Apache-2.0 Imports: 22 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest       = NewError(http.StatusBadRequest, "bad request")
	ErrUnauthorized     = NewError(http.StatusUnauthorized, "unauthorized")
	ErrForbidden        = NewError(http.StatusForbidden, "forbidden")
	ErrNotFound         = NewError(http.StatusNotFound, "not found")
	ErrMethodNotAllowed = NewError(http.StatusMethodNotAllowed, "method not allowed")
	ErrConflict         = NewError(http.StatusConflict, "conflict")
	ErrInternal         = NewError(http.StatusInternalServerError, "internal server error")
)

Functions

func Handle

func Handle(method, path string, handle Handler)

func R

func R() *httprouter.Router

func T

func T(t *testing.T, cases ...TCase)

Types

type Context

type Context struct {
	Request *http.Request
	Writer  http.ResponseWriter
	// contains filtered or unexported fields
}

func (*Context) ATTACHMENT added in v1.7.1

func (c *Context) ATTACHMENT(filepath, filename string)

func (*Context) AllQuery added in v1.7.1

func (c *Context) AllQuery() url.Values

func (*Context) BodyBytes

func (c *Context) BodyBytes() ([]byte, error)

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) FILE added in v1.7.1

func (c *Context) FILE(filepath string)

func (*Context) Get

func (c *Context) Get(key string) (any, bool)

func (*Context) GetAuthorization

func (c *Context) GetAuthorization() string

func (*Context) GetContentType

func (c *Context) GetContentType() string

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

func (*Context) GetRequestId

func (c *Context) GetRequestId() string

func (*Context) GetString

func (c *Context) GetString(key string) string

func (*Context) JSON

func (c *Context) JSON(code int, v any)

func (*Context) JSONOK added in v1.7.1

func (c *Context) JSONOK(v any)

func (*Context) Param

func (c *Context) Param(key string) string

func (*Context) Query

func (c *Context) Query(key string) string

func (*Context) Set

func (c *Context) Set(key string, value any)

func (*Context) SetHeader

func (c *Context) SetHeader(key, value string)

func (*Context) SetStatusCode added in v1.7.1

func (c *Context) SetStatusCode(statusCode int)

func (*Context) TEXT

func (c *Context) TEXT(s string, v ...any)

func (*Context) Value

func (c *Context) Value(key any) any

func (*Context) WithContext added in v1.7.2

func (c *Context) WithContext(ctx context.Context) *Context

type Error

type Error struct {
	Code    int    `json:"code" xml:"code"`
	Message string `json:"message,omitempty" xml:"message,omitempty"`

	Metadata map[string]any `json:"metadata,omitempty" xml:"metadata,omitempty"`
	// contains filtered or unexported fields
}

func NewError

func NewError(code int, s string, v ...any) *Error

func (*Error) AppendMetadata

func (e *Error) AppendMetadata(kvs ...any) *Error

func (*Error) Error

func (e *Error) Error() (s string)

func (*Error) WithMessage added in v1.7.1

func (e *Error) WithMessage(s string, v ...any) *Error

func (*Error) WithMetadata

func (e *Error) WithMetadata(kvs ...any) *Error

type Group

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

func NewGroup

func NewGroup(prefix string, middlewares ...Middleware) *Group

func (*Group) Handle

func (g *Group) Handle(method, path string, handle Handler)

type Handler

type Handler func(c *Context)

func Logger

func Logger(h Handler) Handler

type M

type M = map[string]any

type Middleware

type Middleware func(handle Handler) Handler

type Param

type Param = httprouter.Param

type Params

type Params = httprouter.Params

type TCase

type TCase struct {
	Method string
	Path   string
	Body   string

	Dump bool

	WarpReq func(t *testing.T, req *http.Request)
	Verify  func(t *testing.T, resp *http.Response, code int, body string)
}

Jump to

Keyboard shortcuts

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