apirouter

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 19 Imported by: 1 module, 11 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GoDoc

API router

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, path, verb string) *Context

func NewHttp

func NewHttp(rw http.ResponseWriter, req *http.Request) (*Context, error)

func (*Context) Call

func (c *Context) Call() (any, error)

func (*Context) CallSpecial

func (c *Context) CallSpecial() (any, error)

func (*Context) GetParam

func (c *Context) GetParam(v string) any

func (*Context) GetParamTo

func (c *Context) GetParamTo(v string, obj any) bool

func (*Context) GetParams

func (c *Context) GetParams() any

func (*Context) GetPath

func (c *Context) GetPath() string

func (*Context) NewRequest

func (c *Context) NewRequest(target string) (*http.Request, error)

NewRequest returns a http request for this context (for example for forwarding, etc)

func (*Context) Response

func (c *Context) Response() (res *Response, err error)

func (*Context) ServeHTTP

func (c *Context) ServeHTTP(rw http.ResponseWriter, req *http.Request)

func (*Context) SetHttp

func (c *Context) SetHttp(rw http.ResponseWriter, req *http.Request) error

func (*Context) SetParam

func (c *Context) SetParam(name string, v any)

func (*Context) SetParams

func (c *Context) SetParams(v map[string]any)

func (*Context) SetPath

func (c *Context) SetPath(p string)

func (*Context) Value

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

type Response

type Response struct {
	Result       string   `json:"result"` // error|success|redirect
	Error        string   `json:"error,omitempty"`
	Code         int      `json:"code,omitempty"`
	Time         float64  `json:"time"`
	Data         any      `json:"data"`
	RedirectURL  *url.URL `json:"redirect_url,omitempty"`
	RedirectCode int      `json:"redirect_code,omitempty"`
	// contains filtered or unexported fields
}

func (*Response) ServeHTTP

func (r *Response) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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