Documentation
¶
Index ¶
- Variables
- func GetHeader(ctx context.Context, hdr string) string
- func GetObject[T any](ctx context.Context, typ string) *T
- func GetRequestBody(ctx context.Context) (io.ReadCloser, error)
- func HTTP(rw http.ResponseWriter, req *http.Request)
- func SecurePost(ctx context.Context) error
- type Context
- func (c *Context) Call() (any, error)
- func (c *Context) CallSpecial() (any, error)
- func (c *Context) GetDomain() string
- func (c *Context) GetExtraResponse(k string) any
- func (c *Context) GetObject(typ string) any
- func (c *Context) GetParam(v string) any
- func (c *Context) GetParamTo(v string, obj any) bool
- func (c *Context) GetParams() any
- func (c *Context) GetPath() string
- func (c *Context) GetQuery(v string) any
- func (c *Context) GetQueryFull() map[string]any
- func (c *Context) NewRequest(target string) (*http.Request, error)
- func (c *Context) RequestId() string
- func (c *Context) Response() (res *Response, err error)
- func (c *Context) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (c *Context) SetExtraResponse(k string, v any)
- func (c *Context) SetHttp(rw http.ResponseWriter, req *http.Request) error
- func (c *Context) SetParam(name string, v any)
- func (c *Context) SetParams(v map[string]any)
- func (c *Context) SetPath(p string)
- func (c *Context) Value(v any) any
- type Deletable
- type Error
- type RequestHook
- type Response
- type ResponseHook
- type Updatable
Constants ¶
This section is empty.
Variables ¶
var ( ErrTargetMissing = errors.New("missing target") ErrAccessDenied = &Error{Message: "Access denied", Token: "error_access_denied", Code: http.StatusForbidden} ErrInternal = &Error{Message: "An internal error occured", Token: "error_internal", Code: http.StatusInternalServerError} ErrInsecureRequest = &Error{Message: "Request must use POST and have the appropriate tokens", Token: "error_insecure_request", Code: http.StatusBadRequest} ErrTeapot = &Error{Message: "A teapot has appeared", Token: "error_teapot", Code: http.StatusTeapot} )
var ( RequestHooks []RequestHook ResponseHooks []ResponseHook )
Functions ¶
func GetHeader ¶ added in v0.0.15
GetHeader returns the requested header or an empty string if not found
func GetRequestBody ¶ added in v0.0.15
func GetRequestBody(ctx context.Context) (io.ReadCloser, error)
GetRequestBody returns the current request's body if any, or an error
func HTTP ¶ added in v0.0.2
func HTTP(rw http.ResponseWriter, req *http.Request)
apirouter.HTTP can be used as a handler function, or as a handler via http.HandlerFunc(apirouter.HTTP)
func SecurePost ¶ added in v0.1.7
SecurePost ensures request was a POST request and has the required headers
Types ¶
type Context ¶
func (*Context) CallSpecial ¶
func (*Context) GetExtraResponse ¶ added in v0.0.6
func (*Context) GetQueryFull ¶ added in v0.0.8
func (*Context) NewRequest ¶
NewRequest returns a http request for this context (for example for forwarding, etc)
func (*Context) SetExtraResponse ¶ added in v0.0.6
type Error ¶ added in v0.0.17
type Error struct {
Message string // error message
Code int // HTTP status code for error
Token string // optional error token
}
func (*Error) HTTPStatus ¶ added in v0.0.17
type RequestHook ¶ added in v0.0.20
type Response ¶
type Response struct {
Result string `json:"result"` // error|success|redirect
Error string `json:"error,omitempty"`
Token string `json:"token,omitempty"`
Code int `json:"code,omitempty"`
Debug string `json:"debug,omitempty"`
RequestId string `json:"request_id,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
}