request

package
v0.0.0-...-1388524 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Writer   http.ResponseWriter
	Request  *http.Request
	Response Response
	Context  *RequestContext
	Session  *sessions.Session
}

A Request represents a single HTTP request.

func NewRequest

func NewRequest(w http.ResponseWriter, r *http.Request) *Request

func (*Request) SetValue

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

SetValue sets a request-scoped value with a given key. The value can be retrieved using Value(string)

func (*Request) Value

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

Value retrives a request-scoped value set with SetValue.

func (*Request) Write

func (req *Request) Write(w http.ResponseWriter)

Write writes the Response currently stored in the request to the client.

type RequestContext

type RequestContext struct {
	// ID of the currently logged-in user
	UserID int32
	User   *models.Account
	// The active contest. Generally taken from the hostname -> contest mapping.
	Contest *models.Contest
	// Team of the current logged-in user in the active contest.
	Team *models.Team
	// Locales as set in Accept-Language
	Locales []language.Tag
}

A RequestContext keeps request-scoped information available during a request.

func (*RequestContext) CanSeeProblem

func (rc *RequestContext) CanSeeProblem(problem *models.Problem) bool

type Response

type Response interface {
	// The HTTP status code to return.
	Code() int
}

A Response is the return type of a HTTP processor. It represents the response that should be sent back to the client. This is cached since we may have processors that should be run after the main request handler, but before the response is actually sent.

func BadRequest

func BadRequest(msg string) Response

func Error

func Error(err error) Response

Error returns a 500 Internal Server Error Response wrapping the given error. The error message is not displayed, but it is logged internally.

func NotFound

func NotFound() Response

func Raw

func Raw(content string) Response

Raw returns a Response that renders raw content to the client.

func RawBytes

func RawBytes(content []byte) Response

Raw returns a Response that renders raw content to the client.

func Redirect

func Redirect(url string) Response

Redirect returns a Response that will cause a client to redirect to the given URL.

func Template

func Template(name string, data interface{}) Response

Template returns a Response that renders a given template to the client.

Jump to

Keyboard shortcuts

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