Response

Response retains the mutable state of the HTTP response until the flow is completed.

This API is used in Response.


Symbols

SymbolClassDescription
ResponsetypeResponse defines a public type of API.
NewResponsefuncBuild NewResponse.
ResponseStatustypeResponseStatus defines a public type of API.
ResponseStatus.GetCodefuncReturns the current status code.
ResponseStatus.SetCodefuncSet the status code.
ResponseHeaderstypeResponseHeaders defines a public type of API.
ResponseHeaders.GetfuncIt gets the first value associated with a key.
ResponseHeaders.GetAllfuncIt gets all the values associated with a key.
ResponseHeaders.SetfuncSet or replace a value.
ResponseHeaders.AppendfuncAdd a value without removing existing ones.
ResponseHeaders.DeletefuncEliminates the value associated with a key.
ResponseHeaders.ContainsfuncIt indicates whether a key contains a specific value.
ResponseHeaders.HasfuncIt indicates whether the collection contains the key.
ResponseHeaders.IsEmptyfuncIt indicates whether the collection does not contain values.
ResponseHeaders.CountfuncReturns the number of keys or elements available.
ResponseHeaders.KeysfuncReturns the available keys.
ResponseHeaders.RangefuncWalk the values until the callback requests to stop.
ResponseHeaders.ValuesfuncReturns a copy of the values grouped by key.
ResponseHeaders.EntriesfuncReturn the tickets to the collection.
CookietypeCookie defines a public type of API.
SameSitetypeSameSite defines a public type of API.
SameSiteDefaultconstSameSiteDefault defines a constant value of the API.
SameSiteLaxconstSameSiteLax defines a constant value of the API.
SameSiteStrictconstSameSiteStrict defines a constant value of the API.
SameSiteNoneconstSameSiteNone defines a constant value of the API.
ResponseCookiestypeResponseCookies defines a public type of API.
ResponseCookies.GetfuncIt gets the first value associated with a key.
ResponseCookies.GetAllfuncIt gets all the values associated with a key.
ResponseCookies.SetfuncSet or replace a value.
ResponseCookies.AppendfuncAdd a value without removing existing ones.
ResponseCookies.DeletefuncEliminates the value associated with a key.
ResponseCookies.HasfuncIt indicates whether the collection contains the key.
ResponseCookies.IsEmptyfuncIt indicates whether the collection does not contain values.
ResponseCookies.CountfuncReturns the number of keys or elements available.
ResponseCookies.KeysfuncReturns the available keys.
ResponseCookies.ValuesfuncReturns a copy of the values grouped by key.
ResponseCookies.PendingValuesfuncReturns the cookies to be written.
ResponseCookies.EntriesfuncReturn the tickets to the collection.
Response.DoneWithfuncFinish the response with an optional code and component.
RedirectResponsetypeRedirectResponse defines a public type of API.
RedirectResponse.PermanentfuncIt sets up a permanent redirection.
RedirectResponse.TemporaryfuncIt sets up a temporary redirection.
RedirectResponse.SeeOtherfuncConfigure a redirection 303 See Other.
ResponseImportMaptypeResponseImportMap defines a public type of API.
ResponseImportMap.SetfuncSet or replace a value.
ResponseImportMap.GetfuncIt gets the first value associated with a key.
ResponseImportMap.HasfuncIt indicates whether the collection contains the key.
ResponseImportMap.DeletefuncEliminates the value associated with a key.
ResponseImportMap.LenfuncReturns the declared size.

Response

Declaration:

gox
type Response struct {
	Status       ResponseStatus
	Headers      ResponseHeaders
	Cookies      ResponseCookies
	Redirect     RedirectResponse
	ImportMap    ResponseImportMap
}

Response defines a public type of API.

Fields

FieldTypeDescription
StatusResponseStatusStatus of the operation.
HeadersResponseHeadersHeader collection.
CookiesResponseCookiesCookie collection.
RedirectRedirectResponseRedirection operations.
ImportMapResponseImportMapMap of response imports.

NewResponse

Declaration:

gox
func NewResponse() *Response

Build NewResponse.

Returns

ReturnTypeDescription
value*ResponseType value *Response produced by the operation.

Usage syntax

gox
value := gox.NewResponse()

ResponseStatus

Declaration:

gox
type ResponseStatus struct {
	// contiene campos internos
}

ResponseStatus defines a public type of API.


ResponseStatus.GetCode

Declaration:

gox
func (s *ResponseStatus) GetCode() int

Returns the current status code.

Returns

ReturnTypeDescription
valueintType value int produced by the operation.

Usage syntax

gox
value := ctx.Response.Status.GetCode()

ResponseStatus.SetCode

Declaration:

gox
func (s *ResponseStatus) SetCode(code int)

Set the status code.

Parameters

ParameterTypeDescription
codeintCode of closure.

Usage syntax

gox
ctx.Response.Status.SetCode(200)

ResponseHeaders

Declaration:

gox
type ResponseHeaders struct {
	// contiene campos internos
}

ResponseHeaders defines a public type of API.


ResponseHeaders.Get

Declaration:

gox
func (h *ResponseHeaders) Get(key string) (string, bool)

It gets the first value associated with a key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.
okboolIt indicates the result of the check.

Behavior

When the key does not exist, it returns the zero value of T and false.

Usage syntax

gox
value, ok := ctx.Response.Headers.Get("key")

ResponseHeaders.GetAll

Declaration:

gox
func (h *ResponseHeaders) GetAll(key string) ([]string, bool)

It gets all the values associated with a key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Returns

ReturnTypeDescription
value[]stringResult collection; can be nil when there are no values.
okboolIt indicates the result of the check.

Behavior

The returned slice is independent of the collection. When the key does not exist, it returns nil and false.

Usage syntax

gox
value, ok := ctx.Response.Headers.GetAll("key")

ResponseHeaders.Set

Declaration:

gox
func (h *ResponseHeaders) Set(key string, value string)

Set or replace a value.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.
valuestringValue to be stored or issued.

Behavior

Replace the values previously associated with the same key.

Usage syntax

gox
ctx.Response.Headers.Set("key", value)

ResponseHeaders.Append

Declaration:

gox
func (h *ResponseHeaders) Append(key string, value string)

Add a value without removing existing ones.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.
valuestringValue to be stored or issued.

Behavior

It preserves existing values and adds the new value at the end.

Usage syntax

gox
ctx.Response.Headers.Append("key", value)

ResponseHeaders.Delete

Declaration:

gox
func (h *ResponseHeaders) Delete(key string)

Eliminates the value associated with a key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Behavior

It has no effect when the key does not exist.

Usage syntax

gox
ctx.Response.Headers.Delete("key")

ResponseHeaders.Contains

Declaration:

gox
func (h *ResponseHeaders) Contains(key string, value string) bool

It indicates whether a key contains a specific value.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.
valuestringValue to be stored or issued.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Response.Headers.Contains("key", value)

ResponseHeaders.Has

Declaration:

gox
func (h *ResponseHeaders) Has(key string) bool

It indicates whether the collection contains the key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Response.Headers.Has("key")

ResponseHeaders.IsEmpty

Declaration:

gox
func (h *ResponseHeaders) IsEmpty() bool

It indicates whether the collection does not contain values.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Response.Headers.IsEmpty()

ResponseHeaders.Count

Declaration:

gox
func (h *ResponseHeaders) Count() int

Returns the number of keys or elements available.

Returns

ReturnTypeDescription
valueintType value int produced by the operation.

Usage syntax

gox
value := ctx.Response.Headers.Count()

ResponseHeaders.Keys

Declaration:

gox
func (h *ResponseHeaders) Keys() []string

Returns the available keys.

Returns

ReturnTypeDescription
value[]stringResult collection; can be nil when there are no values.

Behavior

The returned slice can be modified without altering the collection.

Usage syntax

gox
value := ctx.Response.Headers.Keys()

ResponseHeaders.Range

Declaration:

gox
func (h *ResponseHeaders) Range(fn func(key string, value string, first bool) bool)

Walk the values until the callback requests to stop.

Parameters

ParameterTypeDescription
fn func(key stringboolType value bool required by the operation.
value stringboolType value bool required by the operation.
first bool)boolType value bool required by the operation.

Usage syntax

gox
ctx.Response.Headers.Range(value, value, value)

ResponseHeaders.Values

Declaration:

gox
func (h *ResponseHeaders) Values() map[string][]string

Returns a copy of the values grouped by key.

Returns

ReturnTypeDescription
valuemap[string][]stringType value map[string][]string produced by the operation.

Behavior

The returned map is a copy of the visible values.

Usage syntax

gox
value := ctx.Response.Headers.Values()

ResponseHeaders.Entries

Declaration:

gox
func (h *ResponseHeaders) Entries() []Entry[string]

Return the tickets to the collection.

Returns

ReturnTypeDescription
value[]Entry[string]Result collection; can be nil when there are no values.

Behavior

Each input retains the key and all its associated values.

Usage syntax

gox
value := ctx.Response.Headers.Entries()

Declaration:

gox
type Cookie struct {
	Name     string
	Value    string
	Path     string
	Domain   string
	MaxAge   int
	Expires  time.Time
	HttpOnly bool
	Secure   bool
	SameSite SameSite
	Expired  bool
}

Cookie defines a public type of API.

Fields

FieldTypeDescription
NamestringName of the value.
ValuestringValue stored.
PathstringRoute used.
DomainstringCookie domain.
MaxAgeintDuration of the cookie expressed in seconds.
Expirestime.TimeAbsolute expiry date.
HttpOnlyboolRestrict access from JavaScript.
SecureboolState of safe transport.
SameSiteSameSiteSameSite policy.
ExpiredboolMark an expiry cookie.

SameSite

Declaration:

gox
type SameSite int

SameSite defines a public type of API.


SameSiteDefault

Declaration:

gox
SameSiteDefault SameSite = iota

SameSiteDefault defines a constant value of the API.


SameSiteLax

Declaration:

gox
SameSiteLax

SameSiteLax defines a constant value of the API.


SameSiteStrict

Declaration:

gox
SameSiteStrict

SameSiteStrict defines a constant value of the API.


SameSiteNone

Declaration:

gox
SameSiteNone

SameSiteNone defines a constant value of the API.


ResponseCookies

Declaration:

gox
type ResponseCookies struct {
	// contiene campos internos
}

ResponseCookies defines a public type of API.


ResponseCookies.Get

Declaration:

gox
func (c *ResponseCookies) Get(key string) (Cookie, bool)

It gets the first value associated with a key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Returns

ReturnTypeDescription
valueCookieType value Cookie produced by the operation.
okboolIt indicates the result of the check.

Behavior

When the key does not exist, it returns the zero value of T and false.

Usage syntax

gox
value, ok := ctx.Response.Cookies.Get("key")

ResponseCookies.GetAll

Declaration:

gox
func (c *ResponseCookies) GetAll(key string) ([]Cookie, bool)

It gets all the values associated with a key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Returns

ReturnTypeDescription
value[]CookieResult collection; can be nil when there are no values.
okboolIt indicates the result of the check.

Behavior

The returned slice is independent of the collection. When the key does not exist, it returns nil and false.

Usage syntax

gox
value, ok := ctx.Response.Cookies.GetAll("key")

ResponseCookies.Set

Declaration:

gox
func (c *ResponseCookies) Set(cookie Cookie)

Set or replace a value.

Parameters

ParameterTypeDescription
cookieCookieType value Cookie required by the operation.

Behavior

Replace the values previously associated with the same key.

Usage syntax

gox
ctx.Response.Cookies.Set(value)

ResponseCookies.Append

Declaration:

gox
func (c *ResponseCookies) Append(cookie Cookie)

Add a value without removing existing ones.

Parameters

ParameterTypeDescription
cookieCookieType value Cookie required by the operation.

Behavior

It preserves existing values and adds the new value at the end.

Usage syntax

gox
ctx.Response.Cookies.Append(value)

ResponseCookies.Delete

Declaration:

gox
func (c *ResponseCookies) Delete(key string)

Eliminates the value associated with a key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Behavior

It has no effect when the key does not exist.

Usage syntax

gox
ctx.Response.Cookies.Delete("key")

ResponseCookies.Has

Declaration:

gox
func (c *ResponseCookies) Has(key string) bool

It indicates whether the collection contains the key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Response.Cookies.Has("key")

ResponseCookies.IsEmpty

Declaration:

gox
func (c *ResponseCookies) IsEmpty() bool

It indicates whether the collection does not contain values.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Response.Cookies.IsEmpty()

ResponseCookies.Count

Declaration:

gox
func (c *ResponseCookies) Count() int

Returns the number of keys or elements available.

Returns

ReturnTypeDescription
valueintType value int produced by the operation.

Usage syntax

gox
value := ctx.Response.Cookies.Count()

ResponseCookies.Keys

Declaration:

gox
func (c *ResponseCookies) Keys() []string

Returns the available keys.

Returns

ReturnTypeDescription
value[]stringResult collection; can be nil when there are no values.

Behavior

The returned slice can be modified without altering the collection.

Usage syntax

gox
value := ctx.Response.Cookies.Keys()

ResponseCookies.Values

Declaration:

gox
func (c *ResponseCookies) Values() map[string][]Cookie

Returns a copy of the values grouped by key.

Returns

ReturnTypeDescription
valuemap[string][]CookieType value map[string][]Cookie produced by the operation.

Behavior

The returned map is a copy of the visible values.

Usage syntax

gox
value := ctx.Response.Cookies.Values()

ResponseCookies.PendingValues

Declaration:

gox
func (c *ResponseCookies) PendingValues() map[string][]Cookie

Returns the cookies to be written.

Returns

ReturnTypeDescription
valuemap[string][]CookieType value map[string][]Cookie produced by the operation.

Usage syntax

gox
value := ctx.Response.Cookies.PendingValues()

ResponseCookies.Entries

Declaration:

gox
func (c *ResponseCookies) Entries() []Entry[Cookie]

Return the tickets to the collection.

Returns

ReturnTypeDescription
value[]Entry[Cookie]Result collection; can be nil when there are no values.

Behavior

Each input retains the key and all its associated values.

Usage syntax

gox
value := ctx.Response.Cookies.Entries()

Response.DoneWith

Declaration:

gox
func (r *Response) DoneWith(status int, component ...Component)

Finish the response with an optional code and component.

Parameters

ParameterTypeDescription
statusintHTTP status code.
component...ComponentType value ...Component required by the operation.

Behavior

The call stops normal flow and does not support subsequent mutations of the response.

Usage syntax

gox
ctx.Response.DoneWith(200, value)

RedirectResponse

Declaration:

gox
type RedirectResponse struct {
	// contiene campos internos
}

RedirectResponse defines a public type of API.


RedirectResponse.Permanent

Declaration:

gox
func (r RedirectResponse) Permanent(location string)

It sets up a permanent redirection.

Parameters

ParameterTypeDescription
locationstringTarget URL.

Behavior

Finish the response with HTTP code 308.

Usage syntax

gox
ctx.Response.Redirect.Permanent("/path")

RedirectResponse.Temporary

Declaration:

gox
func (r RedirectResponse) Temporary(location string)

It sets up a temporary redirection.

Parameters

ParameterTypeDescription
locationstringTarget URL.

Behavior

Finish the response with HTTP code 307.

Usage syntax

gox
ctx.Response.Redirect.Temporary("/path")

RedirectResponse.SeeOther

Declaration:

gox
func (r RedirectResponse) SeeOther(location string)

Configure a redirection 303 See Other.

Parameters

ParameterTypeDescription
locationstringTarget URL.

Behavior

Finish the response with HTTP code 303.

Usage syntax

gox
ctx.Response.Redirect.SeeOther("/path")

ResponseImportMap

Declaration:

gox
type ResponseImportMap struct {
	// contiene campos internos
}

ResponseImportMap defines a public type of API.


ResponseImportMap.Set

Declaration:

gox
func (m *ResponseImportMap) Set(specifier string, url string)

Set or replace a value.

Parameters

ParameterTypeDescription
specifierstringType value string required by the operation.
urlstringType value string required by the operation.

Behavior

Replace the values previously associated with the same key.

Usage syntax

gox
ctx.Response.ImportMap.Set(value, value)

ResponseImportMap.Get

Declaration:

gox
func (m *ResponseImportMap) Get(specifier string) (string, bool)

It gets the first value associated with a key.

Parameters

ParameterTypeDescription
specifierstringType value string required by the operation.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.
okboolIt indicates the result of the check.

Behavior

When the key does not exist, it returns the zero value of T and false.

Usage syntax

gox
value, ok := ctx.Response.ImportMap.Get(value)

ResponseImportMap.Has

Declaration:

gox
func (m *ResponseImportMap) Has(specifier string) bool

It indicates whether the collection contains the key.

Parameters

ParameterTypeDescription
specifierstringType value string required by the operation.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Response.ImportMap.Has(value)

ResponseImportMap.Delete

Declaration:

gox
func (m *ResponseImportMap) Delete(specifier string)

Eliminates the value associated with a key.

Parameters

ParameterTypeDescription
specifierstringType value string required by the operation.

Behavior

It has no effect when the key does not exist.

Usage syntax

gox
ctx.Response.ImportMap.Delete(value)

ResponseImportMap.Len

Declaration:

gox
func (m *ResponseImportMap) Len() int

Returns the declared size.

Returns

ReturnTypeDescription
valueintType value int produced by the operation.

Usage syntax

gox
value := ctx.Response.ImportMap.Len()

See also

Next step

Continue with File's structure and operations.

File