Documentation ¶
Index ¶
- Constants
- Variables
- func GetHost[T RequestConstraint](r T) string
- type CSRFToken
- type JSONResponse
- type Message
- type Messages
- type Request
- func (r *Request) Error(code int, err string)
- func (r *Request) Form() url.Values
- func (r *Request) FormFileBuffer(name string) (*bytes.Buffer, error)
- func (r *Request) GetData(key string) interface{}
- func (r *Request) Method() string
- func (r *Request) Next() string
- func (r *Request) Redirect(redirectURL string, statuscode int, next ...string)
- func (r *Request) Render(templateName string) error
- func (r *Request) SetData(key string, value interface{})
- func (r *Request) Write(b []byte) (int, error)
- func (r *Request) WriteString(s string) (int, error)
- type RequestConstraint
- type ResponseStatus
- type Session
- type TemplateData
- type URLParams
- type User
Constants ¶
const MESSAGE_COOKIE_NAME = "messages"
const NEXT_COOKIE_NAME = "next"
Variables ¶
var DEFAULT_DATA_FUNC func(r *Request)
Functions ¶
func GetHost ¶
func GetHost[T RequestConstraint](r T) string
Types ¶
type CSRFToken ¶ added in v2.1.4
type CSRFToken struct {
Token string
}
func NewCSRFToken ¶ added in v2.1.4
type JSONResponse ¶
type JSONResponse struct { Next string `json:"next,omitempty"` Detail string `json:"detail,omitempty"` Status ResponseStatus `json:"status"` Data interface{} `json:"data"` }
Default json response which gets returned when using (j).Encode().
type Request ¶
type Request struct { Response http.ResponseWriter Request *http.Request Data *TemplateData Session Session URLParams URLParams User User JSON *_json // contains filtered or unexported fields }
Default request to be passed around the router.
func NewRequest ¶
Initialize a new request.
func (*Request) FormFileBuffer ¶
Get a form file as a buffer.
func (*Request) Next ¶ added in v2.4.4
Get the Next url. This is the url that was set in the session/cookies. This is used to redirect back to the same page.
func (*Request) Redirect ¶ added in v2.4.4
Redirect to a URL. If the session is defined, the messages will be set in the session. If the `next` argument is given, it will be added to session, unless the session is not defined, the `next` parameter will be added to cookies. This means they will be carried across when rendering with request.Render(). This will be set again after the redirect, when rendering in the default Data. Optionally you could obtain this by calling request.Next().
func (*Request) Render ¶ added in v2.3.2
Template configuration must be set before calling this function! See the templates package for more information.
type RequestConstraint ¶
This interface is used to retrieve the request host.
type ResponseStatus ¶
type ResponseStatus string
const ( ResponseStatusOK ResponseStatus = "ok" ResponseStatusError ResponseStatus = "error" ResponseStatusRedirect ResponseStatus = "redirect" )
type Session ¶ added in v2.3.6
type Session interface { Set(key string, value interface{}) Get(key string) interface{} Exists(key string) bool Delete(key string) Destroy() error }
This interface will be set on the request, but is only useful if any middleware is using it. If no middleware has set it, it will remain unused.
type TemplateData ¶ added in v2.1.4
type TemplateData struct { Data map[string]any Messages Messages CSRFToken *CSRFToken User interface{} Next string }
func NewTemplateData ¶ added in v2.1.4
func NewTemplateData() *TemplateData
func (*TemplateData) AddMessage ¶ added in v2.1.4
func (td *TemplateData) AddMessage(messageType, message string)
func (*TemplateData) Delete ¶ added in v2.1.4
func (td *TemplateData) Delete(key string)
func (*TemplateData) Get ¶ added in v2.1.4
func (td *TemplateData) Get(key string) interface{}
func (*TemplateData) Has ¶ added in v2.1.4
func (td *TemplateData) Has(key string) bool
func (*TemplateData) Set ¶ added in v2.1.4
func (td *TemplateData) Set(key string, value interface{})
type User ¶ added in v2.0.1
type User interface {
IsAuthenticated() bool
}
Default request user interface. This interface is used to check if a user is authenticated. This interface is used by the LoginRequiredMiddleware and LogoutRequiredMiddleware. If you want to use these middlewares, you should implement this interface. And set the GetRequestUserFunc function to return a user.