Response
Response retains the mutable state of the HTTP response until the flow is completed.
This API is used in Response.
Symbols
| Symbol | Class | Description |
|---|---|---|
| Response | type | Response defines a public type of API. |
| NewResponse | func | Build NewResponse. |
| ResponseStatus | type | ResponseStatus defines a public type of API. |
| ResponseStatus.GetCode | func | Returns the current status code. |
| ResponseStatus.SetCode | func | Set the status code. |
| ResponseHeaders | type | ResponseHeaders defines a public type of API. |
| ResponseHeaders.Get | func | It gets the first value associated with a key. |
| ResponseHeaders.GetAll | func | It gets all the values associated with a key. |
| ResponseHeaders.Set | func | Set or replace a value. |
| ResponseHeaders.Append | func | Add a value without removing existing ones. |
| ResponseHeaders.Delete | func | Eliminates the value associated with a key. |
| ResponseHeaders.Contains | func | It indicates whether a key contains a specific value. |
| ResponseHeaders.Has | func | It indicates whether the collection contains the key. |
| ResponseHeaders.IsEmpty | func | It indicates whether the collection does not contain values. |
| ResponseHeaders.Count | func | Returns the number of keys or elements available. |
| ResponseHeaders.Keys | func | Returns the available keys. |
| ResponseHeaders.Range | func | Walk the values until the callback requests to stop. |
| ResponseHeaders.Values | func | Returns a copy of the values grouped by key. |
| ResponseHeaders.Entries | func | Return the tickets to the collection. |
| Cookie | type | Cookie defines a public type of API. |
| SameSite | type | SameSite defines a public type of API. |
| SameSiteDefault | const | SameSiteDefault defines a constant value of the API. |
| SameSiteLax | const | SameSiteLax defines a constant value of the API. |
| SameSiteStrict | const | SameSiteStrict defines a constant value of the API. |
| SameSiteNone | const | SameSiteNone defines a constant value of the API. |
| ResponseCookies | type | ResponseCookies defines a public type of API. |
| ResponseCookies.Get | func | It gets the first value associated with a key. |
| ResponseCookies.GetAll | func | It gets all the values associated with a key. |
| ResponseCookies.Set | func | Set or replace a value. |
| ResponseCookies.Append | func | Add a value without removing existing ones. |
| ResponseCookies.Delete | func | Eliminates the value associated with a key. |
| ResponseCookies.Has | func | It indicates whether the collection contains the key. |
| ResponseCookies.IsEmpty | func | It indicates whether the collection does not contain values. |
| ResponseCookies.Count | func | Returns the number of keys or elements available. |
| ResponseCookies.Keys | func | Returns the available keys. |
| ResponseCookies.Values | func | Returns a copy of the values grouped by key. |
| ResponseCookies.PendingValues | func | Returns the cookies to be written. |
| ResponseCookies.Entries | func | Return the tickets to the collection. |
| Response.DoneWith | func | Finish the response with an optional code and component. |
| RedirectResponse | type | RedirectResponse defines a public type of API. |
| RedirectResponse.Permanent | func | It sets up a permanent redirection. |
| RedirectResponse.Temporary | func | It sets up a temporary redirection. |
| RedirectResponse.SeeOther | func | Configure a redirection 303 See Other. |
| ResponseImportMap | type | ResponseImportMap defines a public type of API. |
| ResponseImportMap.Set | func | Set or replace a value. |
| ResponseImportMap.Get | func | It gets the first value associated with a key. |
| ResponseImportMap.Has | func | It indicates whether the collection contains the key. |
| ResponseImportMap.Delete | func | Eliminates the value associated with a key. |
| ResponseImportMap.Len | func | Returns the declared size. |
Response
Declaration:
type Response struct {
Status ResponseStatus
Headers ResponseHeaders
Cookies ResponseCookies
Redirect RedirectResponse
ImportMap ResponseImportMap
} Response defines a public type of API.
Fields
| Field | Type | Description |
|---|---|---|
Status | ResponseStatus | Status of the operation. |
Headers | ResponseHeaders | Header collection. |
Cookies | ResponseCookies | Cookie collection. |
Redirect | RedirectResponse | Redirection operations. |
ImportMap | ResponseImportMap | Map of response imports. |
NewResponse
Declaration:
func NewResponse() *Response Build NewResponse.
Returns
| Return | Type | Description |
|---|---|---|
value | *Response | Type value *Response produced by the operation. |
Usage syntax
value := gox.NewResponse() ResponseStatus
Declaration:
type ResponseStatus struct {
// contiene campos internos
} ResponseStatus defines a public type of API.
ResponseStatus.GetCode
Declaration:
func (s *ResponseStatus) GetCode() int Returns the current status code.
Returns
| Return | Type | Description |
|---|---|---|
value | int | Type value int produced by the operation. |
Usage syntax
value := ctx.Response.Status.GetCode() ResponseStatus.SetCode
Declaration:
func (s *ResponseStatus) SetCode(code int) Set the status code.
Parameters
| Parameter | Type | Description |
|---|---|---|
code | int | Code of closure. |
Usage syntax
ctx.Response.Status.SetCode(200) ResponseHeaders
Declaration:
type ResponseHeaders struct {
// contiene campos internos
} ResponseHeaders defines a public type of API.
ResponseHeaders.Get
Declaration:
func (h *ResponseHeaders) Get(key string) (string, bool) It gets the first value associated with a key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
Returns
| Return | Type | Description |
|---|---|---|
value | string | Textual value produced by the operation; its zero value is an empty string. |
ok | bool | It indicates the result of the check. |
Behavior
When the key does not exist, it returns the zero value of T and false.
Usage syntax
value, ok := ctx.Response.Headers.Get("key") ResponseHeaders.GetAll
Declaration:
func (h *ResponseHeaders) GetAll(key string) ([]string, bool) It gets all the values associated with a key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
Returns
| Return | Type | Description |
|---|---|---|
value | []string | Result collection; can be nil when there are no values. |
ok | bool | It 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
value, ok := ctx.Response.Headers.GetAll("key") ResponseHeaders.Set
Declaration:
func (h *ResponseHeaders) Set(key string, value string) Set or replace a value.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
value | string | Value to be stored or issued. |
Behavior
Replace the values previously associated with the same key.
Usage syntax
ctx.Response.Headers.Set("key", value) ResponseHeaders.Append
Declaration:
func (h *ResponseHeaders) Append(key string, value string) Add a value without removing existing ones.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
value | string | Value to be stored or issued. |
Behavior
It preserves existing values and adds the new value at the end.
Usage syntax
ctx.Response.Headers.Append("key", value) ResponseHeaders.Delete
Declaration:
func (h *ResponseHeaders) Delete(key string) Eliminates the value associated with a key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
Behavior
It has no effect when the key does not exist.
Usage syntax
ctx.Response.Headers.Delete("key") ResponseHeaders.Contains
Declaration:
func (h *ResponseHeaders) Contains(key string, value string) bool It indicates whether a key contains a specific value.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
value | string | Value to be stored or issued. |
Returns
| Return | Type | Description |
|---|---|---|
value | bool | It indicates the result of the check. |
Usage syntax
value := ctx.Response.Headers.Contains("key", value) ResponseHeaders.Has
Declaration:
func (h *ResponseHeaders) Has(key string) bool It indicates whether the collection contains the key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
Returns
| Return | Type | Description |
|---|---|---|
value | bool | It indicates the result of the check. |
Usage syntax
value := ctx.Response.Headers.Has("key") ResponseHeaders.IsEmpty
Declaration:
func (h *ResponseHeaders) IsEmpty() bool It indicates whether the collection does not contain values.
Returns
| Return | Type | Description |
|---|---|---|
value | bool | It indicates the result of the check. |
Usage syntax
value := ctx.Response.Headers.IsEmpty() ResponseHeaders.Count
Declaration:
func (h *ResponseHeaders) Count() int Returns the number of keys or elements available.
Returns
| Return | Type | Description |
|---|---|---|
value | int | Type value int produced by the operation. |
Usage syntax
value := ctx.Response.Headers.Count() ResponseHeaders.Keys
Declaration:
func (h *ResponseHeaders) Keys() []string Returns the available keys.
Returns
| Return | Type | Description |
|---|---|---|
value | []string | Result collection; can be nil when there are no values. |
Behavior
The returned slice can be modified without altering the collection.
Usage syntax
value := ctx.Response.Headers.Keys() ResponseHeaders.Range
Declaration:
func (h *ResponseHeaders) Range(fn func(key string, value string, first bool) bool) Walk the values until the callback requests to stop.
Parameters
| Parameter | Type | Description |
|---|---|---|
fn func(key string | bool | Type value bool required by the operation. |
value string | bool | Type value bool required by the operation. |
first bool) | bool | Type value bool required by the operation. |
Usage syntax
ctx.Response.Headers.Range(value, value, value) ResponseHeaders.Values
Declaration:
func (h *ResponseHeaders) Values() map[string][]string Returns a copy of the values grouped by key.
Returns
| Return | Type | Description |
|---|---|---|
value | map[string][]string | Type value map[string][]string produced by the operation. |
Behavior
The returned map is a copy of the visible values.
Usage syntax
value := ctx.Response.Headers.Values() ResponseHeaders.Entries
Declaration:
func (h *ResponseHeaders) Entries() []Entry[string] Return the tickets to the collection.
Returns
| Return | Type | Description |
|---|---|---|
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
value := ctx.Response.Headers.Entries() Cookie
Declaration:
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
| Field | Type | Description |
|---|---|---|
Name | string | Name of the value. |
Value | string | Value stored. |
Path | string | Route used. |
Domain | string | Cookie domain. |
MaxAge | int | Duration of the cookie expressed in seconds. |
Expires | time.Time | Absolute expiry date. |
HttpOnly | bool | Restrict access from JavaScript. |
Secure | bool | State of safe transport. |
SameSite | SameSite | SameSite policy. |
Expired | bool | Mark an expiry cookie. |
SameSite
Declaration:
type SameSite int SameSite defines a public type of API.
SameSiteDefault
Declaration:
SameSiteDefault SameSite = iota SameSiteDefault defines a constant value of the API.
SameSiteLax
Declaration:
SameSiteLax SameSiteLax defines a constant value of the API.
SameSiteStrict
Declaration:
SameSiteStrict SameSiteStrict defines a constant value of the API.
SameSiteNone
Declaration:
SameSiteNone SameSiteNone defines a constant value of the API.
ResponseCookies
Declaration:
type ResponseCookies struct {
// contiene campos internos
} ResponseCookies defines a public type of API.
ResponseCookies.Get
Declaration:
func (c *ResponseCookies) Get(key string) (Cookie, bool) It gets the first value associated with a key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
Returns
| Return | Type | Description |
|---|---|---|
value | Cookie | Type value Cookie produced by the operation. |
ok | bool | It indicates the result of the check. |
Behavior
When the key does not exist, it returns the zero value of T and false.
Usage syntax
value, ok := ctx.Response.Cookies.Get("key") ResponseCookies.GetAll
Declaration:
func (c *ResponseCookies) GetAll(key string) ([]Cookie, bool) It gets all the values associated with a key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
Returns
| Return | Type | Description |
|---|---|---|
value | []Cookie | Result collection; can be nil when there are no values. |
ok | bool | It 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
value, ok := ctx.Response.Cookies.GetAll("key") ResponseCookies.Set
Declaration:
func (c *ResponseCookies) Set(cookie Cookie) Set or replace a value.
Parameters
| Parameter | Type | Description |
|---|---|---|
cookie | Cookie | Type value Cookie required by the operation. |
Behavior
Replace the values previously associated with the same key.
Usage syntax
ctx.Response.Cookies.Set(value) ResponseCookies.Append
Declaration:
func (c *ResponseCookies) Append(cookie Cookie) Add a value without removing existing ones.
Parameters
| Parameter | Type | Description |
|---|---|---|
cookie | Cookie | Type value Cookie required by the operation. |
Behavior
It preserves existing values and adds the new value at the end.
Usage syntax
ctx.Response.Cookies.Append(value) ResponseCookies.Delete
Declaration:
func (c *ResponseCookies) Delete(key string) Eliminates the value associated with a key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
Behavior
It has no effect when the key does not exist.
Usage syntax
ctx.Response.Cookies.Delete("key") ResponseCookies.Has
Declaration:
func (c *ResponseCookies) Has(key string) bool It indicates whether the collection contains the key.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Key that identifies the value. |
Returns
| Return | Type | Description |
|---|---|---|
value | bool | It indicates the result of the check. |
Usage syntax
value := ctx.Response.Cookies.Has("key") ResponseCookies.IsEmpty
Declaration:
func (c *ResponseCookies) IsEmpty() bool It indicates whether the collection does not contain values.
Returns
| Return | Type | Description |
|---|---|---|
value | bool | It indicates the result of the check. |
Usage syntax
value := ctx.Response.Cookies.IsEmpty() ResponseCookies.Count
Declaration:
func (c *ResponseCookies) Count() int Returns the number of keys or elements available.
Returns
| Return | Type | Description |
|---|---|---|
value | int | Type value int produced by the operation. |
Usage syntax
value := ctx.Response.Cookies.Count() ResponseCookies.Keys
Declaration:
func (c *ResponseCookies) Keys() []string Returns the available keys.
Returns
| Return | Type | Description |
|---|---|---|
value | []string | Result collection; can be nil when there are no values. |
Behavior
The returned slice can be modified without altering the collection.
Usage syntax
value := ctx.Response.Cookies.Keys() ResponseCookies.Values
Declaration:
func (c *ResponseCookies) Values() map[string][]Cookie Returns a copy of the values grouped by key.
Returns
| Return | Type | Description |
|---|---|---|
value | map[string][]Cookie | Type value map[string][]Cookie produced by the operation. |
Behavior
The returned map is a copy of the visible values.
Usage syntax
value := ctx.Response.Cookies.Values() ResponseCookies.PendingValues
Declaration:
func (c *ResponseCookies) PendingValues() map[string][]Cookie Returns the cookies to be written.
Returns
| Return | Type | Description |
|---|---|---|
value | map[string][]Cookie | Type value map[string][]Cookie produced by the operation. |
Usage syntax
value := ctx.Response.Cookies.PendingValues() ResponseCookies.Entries
Declaration:
func (c *ResponseCookies) Entries() []Entry[Cookie] Return the tickets to the collection.
Returns
| Return | Type | Description |
|---|---|---|
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
value := ctx.Response.Cookies.Entries() Response.DoneWith
Declaration:
func (r *Response) DoneWith(status int, component ...Component) Finish the response with an optional code and component.
Parameters
| Parameter | Type | Description |
|---|---|---|
status | int | HTTP status code. |
component | ...Component | Type value ...Component required by the operation. |
Behavior
The call stops normal flow and does not support subsequent mutations of the response.
Usage syntax
ctx.Response.DoneWith(200, value) RedirectResponse
Declaration:
type RedirectResponse struct {
// contiene campos internos
} RedirectResponse defines a public type of API.
RedirectResponse.Permanent
Declaration:
func (r RedirectResponse) Permanent(location string) It sets up a permanent redirection.
Parameters
| Parameter | Type | Description |
|---|---|---|
location | string | Target URL. |
Behavior
Finish the response with HTTP code 308.
Usage syntax
ctx.Response.Redirect.Permanent("/path") RedirectResponse.Temporary
Declaration:
func (r RedirectResponse) Temporary(location string) It sets up a temporary redirection.
Parameters
| Parameter | Type | Description |
|---|---|---|
location | string | Target URL. |
Behavior
Finish the response with HTTP code 307.
Usage syntax
ctx.Response.Redirect.Temporary("/path") RedirectResponse.SeeOther
Declaration:
func (r RedirectResponse) SeeOther(location string) Configure a redirection 303 See Other.
Parameters
| Parameter | Type | Description |
|---|---|---|
location | string | Target URL. |
Behavior
Finish the response with HTTP code 303.
Usage syntax
ctx.Response.Redirect.SeeOther("/path") ResponseImportMap
Declaration:
type ResponseImportMap struct {
// contiene campos internos
} ResponseImportMap defines a public type of API.
ResponseImportMap.Set
Declaration:
func (m *ResponseImportMap) Set(specifier string, url string) Set or replace a value.
Parameters
| Parameter | Type | Description |
|---|---|---|
specifier | string | Type value string required by the operation. |
url | string | Type value string required by the operation. |
Behavior
Replace the values previously associated with the same key.
Usage syntax
ctx.Response.ImportMap.Set(value, value) ResponseImportMap.Get
Declaration:
func (m *ResponseImportMap) Get(specifier string) (string, bool) It gets the first value associated with a key.
Parameters
| Parameter | Type | Description |
|---|---|---|
specifier | string | Type value string required by the operation. |
Returns
| Return | Type | Description |
|---|---|---|
value | string | Textual value produced by the operation; its zero value is an empty string. |
ok | bool | It indicates the result of the check. |
Behavior
When the key does not exist, it returns the zero value of T and false.
Usage syntax
value, ok := ctx.Response.ImportMap.Get(value) ResponseImportMap.Has
Declaration:
func (m *ResponseImportMap) Has(specifier string) bool It indicates whether the collection contains the key.
Parameters
| Parameter | Type | Description |
|---|---|---|
specifier | string | Type value string required by the operation. |
Returns
| Return | Type | Description |
|---|---|---|
value | bool | It indicates the result of the check. |
Usage syntax
value := ctx.Response.ImportMap.Has(value) ResponseImportMap.Delete
Declaration:
func (m *ResponseImportMap) Delete(specifier string) Eliminates the value associated with a key.
Parameters
| Parameter | Type | Description |
|---|---|---|
specifier | string | Type value string required by the operation. |
Behavior
It has no effect when the key does not exist.
Usage syntax
ctx.Response.ImportMap.Delete(value) ResponseImportMap.Len
Declaration:
func (m *ResponseImportMap) Len() int Returns the declared size.
Returns
| Return | Type | Description |
|---|---|---|
value | int | Type value int produced by the operation. |
Usage syntax
value := ctx.Response.ImportMap.Len()