Documentation ¶
Index ¶
- Constants
- func AddHeader(w http.ResponseWriter, name, value string)
- func GetHost[T RequestConstraint](r T) string
- type CSRFToken
- type LogLevel
- type Logger
- type Message
- type Messages
- type NopLogger
- func (l *NopLogger) Critical(err error)
- func (l *NopLogger) Criticalf(format string, args ...interface{})
- func (l *NopLogger) Debug(args ...interface{})
- func (l *NopLogger) Debugf(format string, args ...interface{})
- func (l *NopLogger) Error(args ...interface{})
- func (l *NopLogger) Errorf(format string, args ...interface{})
- func (l *NopLogger) Info(args ...interface{})
- func (l *NopLogger) Infof(format string, args ...interface{})
- func (l *NopLogger) LogLevel() LogLevel
- func (l *NopLogger) Test(args ...interface{})
- func (l *NopLogger) Testf(format string, args ...interface{})
- func (l *NopLogger) Warning(args ...interface{})
- func (l *NopLogger) Warningf(format string, args ...interface{})
- type Request
- func (r *Request) AddHeader(name, value string)
- func (r *Request) Context() context.Context
- func (r *Request) DeleteCookie(name string)
- 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) GetCookie(name string) (*http.Cookie, error)
- func (r *Request) GetData(key string) interface{}
- func (r *Request) GetHeader(name string) string
- func (r *Request) IP() string
- func (r *Request) Method() string
- func (r *Request) Next() string
- func (r *Request) ReSetNext()
- func (r *Request) Redirect(redirectURL string, statuscode int, next ...string)
- func (r *Request) SetCookies(cookies ...*http.Cookie)
- func (r *Request) SetData(key string, value interface{})
- func (r *Request) SetHeader(name, value string)
- func (r *Request) Write(b []byte) (int, error)
- func (r *Request) WriteString(s string) (int, error)
- type RequestConstraint
- type Session
- type TemplateData
- type TemplateRequest
- type User
Constants ¶
const MESSAGE_COOKIE_NAME = "messages"
const NEXT_COOKIE_NAME = "next"
Variables ¶
This section is empty.
Functions ¶
func AddHeader ¶
func AddHeader(w http.ResponseWriter, name, value string)
Add a header onto the request. This will append the value to the current value. If the value already exists, it will not be added.
func GetHost ¶
func GetHost[T RequestConstraint](r T) string
Types ¶
type Logger ¶
type Logger interface { // Write a critical error message // // This message should be handled differently // // than the other ways of reporting. Critical(err error) // Format and write a critical error message Criticalf(format string, args ...any) // Write an error message, loglevel error Error(args ...any) Errorf(format string, args ...any) // Write a warning message, loglevel warning Warning(args ...any) Warningf(format string, args ...any) // Write an info message, loglevel info Info(args ...any) Infof(format string, args ...any) // Write a debug message, loglevel debug Debug(args ...any) Debugf(format string, args ...any) // Write a test message, loglevel test Test(args ...any) Testf(format string, args ...any) // Retrieve the loglevel LogLevel() LogLevel }
Default logger interface, can be used to set a logger on the request.
This logger can be set in for example, the middleware, and then be used in the views by the request.
func NewNopLogger ¶ added in v3.3.4
func NewNopLogger() Logger
type NopLogger ¶ added in v3.3.4
type NopLogger struct{}
type Request ¶
type Request struct { // Underlying http response writer. Response writer.ClearableBufferedResponse // Underlying http request. Request *http.Request // Default data to be passed to any possible templates. Data *TemplateData // URL Parameters set inside of the router. URLParams params.URLParams // Query parameters set inside of the router. QueryParams url.Values // Interfaces which can be set using the right middlewares. // These interfaces are not set by default, but can be set by middleware. User User // Session can be set with middleware! Session Session // Logger can be set with middleware! Logger Logger // URL Func will be automatically set by the router. URL func(method, name string) routevars.URLFormatter // contains filtered or unexported fields }
Default request to be passed around the router.
func NewRequest ¶
func NewRequest(writer writer.ClearableBufferedResponse, request *http.Request, params params.URLParams) *Request
Initialize a new request.
func (*Request) Error ¶
Raise an error.
This will clear any buffered response, and set the error code.
func (*Request) FormFileBuffer ¶
Get a form file as a buffer.
func (*Request) Next ¶
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 ¶
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().
type RequestConstraint ¶
This constraint is used to retrieve the request host.
type Session ¶
type Session interface { Set(key string, value interface{}) Get(key string) interface{} Exists(key string) bool Delete(key string) Destroy() error RenewToken() 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 ¶
type TemplateData struct { Data map[string]any Messages Messages CSRFToken *CSRFToken Request *TemplateRequest }
func NewTemplateData ¶
func NewTemplateData() *TemplateData
func (*TemplateData) AddMessage ¶
func (td *TemplateData) AddMessage(messageType, message string)
func (*TemplateData) Delete ¶
func (td *TemplateData) Delete(key string)
func (*TemplateData) Get ¶
func (td *TemplateData) Get(key string) interface{}
func (*TemplateData) Has ¶
func (td *TemplateData) Has(key string) bool
func (*TemplateData) Set ¶
func (td *TemplateData) Set(key string, value interface{})
type TemplateRequest ¶ added in v3.1.3
func (*TemplateRequest) URL ¶ added in v3.1.3
func (tr *TemplateRequest) URL(path string, args ...interface{}) string
type User ¶
type User interface { // Check if the user is authenticated IsAuthenticated() bool // Check if the user is an administator IsAdmin() bool // Check permissions, if the user is an admin, this should return true. HasPermissions(permissions ...string) 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.