Documentation
¶
Index ¶
- Variables
- func CSRFHeaderHook(c *Context) error
- func GetHeader(ctx context.Context, hdr string) string
- func GetInputJSON[T ~[]byte](ctx context.Context) T
- func GetObject[T any](ctx context.Context, typ string) *T
- func GetParam[T any](ctx context.Context, v string) (T, bool)
- func GetRequestBody(ctx context.Context) (io.ReadCloser, error)
- func GetUser[T any](ctx context.Context) *T
- 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() map[string]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) SetCsrfValidated(ok bool)
- 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) SetUser(user any)
- 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 CSRFHeaderHook ¶ added in v0.1.8
CSRFHeaderHook is a sample hook for checking a specific middleware header for csrf validation
func GetHeader ¶ added in v0.0.15
GetHeader returns the requested header or an empty string if not found
func GetInputJSON ¶ added in v0.1.11
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 GetUser ¶ added in v0.1.8
GetUser will return the user object if it matches type T. If there is no user object or it is not of the right type, nil will be returned
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) GetParam ¶
GetParam returns one individual value from the current parameters, and can lookup valuyes in submaps/etc by adding a dot between values.
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) SetCsrfValidated ¶ added in v0.1.8
SetCsrfValidated is to be used in request hook to tell apirouter if the request came with a valid and appropriate CSRF token.
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
}