request

package
v2.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func NewCSRFToken(token string) *CSRFToken

func (*CSRFToken) Input added in v2.1.4

func (ct *CSRFToken) Input() template.HTML

func (*CSRFToken) String added in v2.1.4

func (ct *CSRFToken) String() string

type JSONResponse

type JSONResponse struct {
	Status ResponseStatus `json:"status"`
	Data   interface{}    `json:"data"`
}

Default json response which gets returned when using (j).Encode().

type Message added in v2.1.4

type Message struct {
	Type string
	Text string
}

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

func NewRequest(writer http.ResponseWriter, request *http.Request, params URLParams) *Request

Initialize a new request.

func (*Request) Error

func (r *Request) Error(code int, err string)

Raise an error.

func (*Request) Form

func (r *Request) Form() url.Values

Parse the form, and return the form values.

func (*Request) FormFileBuffer

func (r *Request) FormFileBuffer(name string) (*bytes.Buffer, error)

Get a form file as a buffer.

func (*Request) GetData

func (r *Request) GetData(key string) interface{}

Get a data value.

func (*Request) IsGet

func (r *Request) IsGet() bool

Check if the request method is GET.

func (*Request) IsPost

func (r *Request) IsPost() bool

Check if the request method is POST.

func (*Request) Method

func (r *Request) Method() string

Get the request method.

func (*Request) Render added in v2.3.2

func (r *Request) Render(templateName string) error

Template configuration must be set before calling this function! See the templates package for more information.

func (*Request) SetData

func (r *Request) SetData(key string, value interface{})

Set a data value.

func (*Request) Write added in v2.0.6

func (r *Request) Write(b []byte) (int, error)

Write to the response.

func (*Request) WriteString added in v2.0.6

func (r *Request) WriteString(s string) (int, error)

Write a string to the response.

type RequestConstraint

type RequestConstraint interface {
	*Request | *http.Request
}

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
	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  []Message
	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 URLParams

type URLParams map[string]string

func (URLParams) Get

func (u URLParams) Get(key string, def ...string) string

func (URLParams) GetInt

func (u URLParams) GetInt(key string, def ...int) int

func (URLParams) Has

func (u URLParams) Has(key string) bool

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.

Jump to

Keyboard shortcuts

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