Request

Request represents the normalized HTTP request and exposes its URL, path, collections, form, and body.

This API is used in Request, Routes.


Symbols

SymbolClassDescription
RequesttypeRequest defines a public type of API.
FormDatatypeBuild a body multipart/form-data.
RequestInputtypeRequestInput defines a public type of API.
NewRequestfuncBuild NewRequest.
Request.MethodfuncReturns the HTTP method or the solved method name.
Request.IPfuncReturns the IP address resolved for the client.
Request.IsSecurefuncIt indicates whether the request uses safe transport.
Request.ContentTypefuncReturn the MIME type.
URLtypeURL defines a public type of API.
URLInputtypeURLInput defines a public type of API.
NewURLfuncBuild NewURL.
URL.StringfuncReturns the full textual representation.
URL.SchemefuncReturns the URL schema.
URL.HostfuncReturn host and port.
URL.HostnamefuncReturn the hostname without port.
URL.PortfuncReturn the explicit port.
URL.PathfuncReturns the standard route.
URL.RawPathfuncReturns the original encoded route.
URL.QueryStringfuncReturns the query string without analysis.
URL.OriginfuncReturns schema and authority.
RoutetypeRoute defines a public type of API.
RouteInputtypeRouteInput defines a public type of API.
NewRoutefuncBuild NewRoute.
Route.IsMatchedfuncIt indicates whether a set-up rule produced the route.
Route.OriginalfuncReturns the requested route before the resolution.
Route.TargetfuncReturns the resolved internal destination.
Route.PatternfuncReturns the pattern that produced the coincidence.
Route.MethodfuncReturns the HTTP method or the solved method name.
Route.IsStaticfuncIt indicates if the destination is a static file.
Route.IsActionfuncIt indicates if the fate is an Action.
Route.IsClientAssetfuncIt indicates whether the destination belongs to a Client component.
EntrytypeEntry defines a public type of API.
CollectiontypeCollection defines a public type of API.
NewCollectionfuncBuild NewCollection.
NewCollectionViewfuncBuild NewCollectionView.
Collection.GetfuncIt gets the first value associated with a key.
Collection.GetAllfuncIt gets all the values associated with a key.
Collection.HasfuncIt indicates whether the collection contains the key.
Collection.IsEmptyfuncIt indicates whether the collection does not contain values.
Collection.CountfuncReturns the number of keys or elements available.
Collection.KeysfuncReturns the available keys.
Collection.ValuesfuncReturns a copy of the values grouped by key.
Collection.EntriesfuncReturn the tickets to the collection.
NewHeadersfuncBuild NewHeaders.
NewCookiesfuncBuild NewCookies.

Request

Declaration:

gox
type Request struct {
	URL     URL
	Headers Collection[string]
	Cookies Collection[string]
	Query   Collection[string]
	Form    FormData
	Route   Route
	Body    Body
}

Request defines a public type of API.

Fields

FieldTypeDescription
URLURLStructured request URL.
HeadersCollection[string]Header collection.
CookiesCollection[string]Cookie collection.
QueryCollection[string]query parameters.
FormFormDataForm fields.
RouteRouteResult of road resolution.
BodyBodyrequest body.

FormData

Declaration:

gox
type FormData struct {
	Fields Collection[string]
	Files  Collection[File]
}

Build a body multipart/form-data.

Fields

FieldTypeDescription
FieldsCollection[string]Text fields.
FilesCollection[File]Files received.

RequestInput

Declaration:

gox
type RequestInput struct {
	Method      string
	IP          string
	Secure      bool
	ContentType string
	URL     URL
	Headers Collection[string]
	Cookies Collection[string]
	Query   Collection[string]
	Form    Collection[string]
	Files   Collection[File]
	Route   Route
	Body    Body
}

RequestInput defines a public type of API.

Fields

FieldTypeDescription
MethodstringHTTP method or Action name.
IPstringIP address solved.
SecureboolState of safe transport.
ContentTypestringHalf type declared.
URLURLStructured request URL.
HeadersCollection[string]Header collection.
CookiesCollection[string]Cookie collection.
QueryCollection[string]query parameters.
FormCollection[string]Form fields.
FilesCollection[File]Files received.
RouteRouteResult of road resolution.
BodyBodyrequest body.

NewRequest

Declaration:

gox
func NewRequest(input RequestInput) Request

Build NewRequest.

Parameters

ParameterTypeDescription
inputRequestInputData used to build the value.

Returns

ReturnTypeDescription
valueRequestType value Request produced by the operation.

Usage syntax

gox
value := gox.NewRequest(gox.RequestInput{})

Request.Method

Declaration:

gox
func (r Request) Method() string

Returns the HTTP method or the solved method name.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.Method()

Request.IP

Declaration:

gox
func (r Request) IP() string

Returns the IP address resolved for the client.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.IP()

Request.IsSecure

Declaration:

gox
func (r Request) IsSecure() bool

It indicates whether the request uses safe transport.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Request.IsSecure()

Request.ContentType

Declaration:

gox
func (r Request) ContentType() string

Return the MIME type.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.ContentType()

URL

Declaration:

gox
type URL struct {
	// contiene campos internos
}

URL defines a public type of API.


URLInput

Declaration:

gox
type URLInput struct {
	String      string
	Scheme      string
	Host        string
	Hostname    string
	Port        string
	Path        string
	RawPath     string
	QueryString string
}

URLInput defines a public type of API.

Fields

FieldTypeDescription
StringstringFull URL provided as input.
SchemestringURL outline.
HoststringHost, including the port when it exists.
HostnamestringName of host without port.
PortstringExplicit URL port.
PathstringRoute used.
RawPathstringOriginal encoded route.
QueryStringstringQuery string without the leading question mark.

NewURL

Declaration:

gox
func NewURL(input URLInput) URL

Build NewURL.

Parameters

ParameterTypeDescription
inputURLInputData used to build the value.

Returns

ReturnTypeDescription
valueURLType value URL produced by the operation.

Usage syntax

gox
value := gox.NewURL(gox.URLInput{})

URL.String

Declaration:

gox
func (u URL) String() string

Returns the full textual representation.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.URL.String()

URL.Scheme

Declaration:

gox
func (u URL) Scheme() string

Returns the URL schema.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.URL.Scheme()

URL.Host

Declaration:

gox
func (u URL) Host() string

Return host and port.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.URL.Host()

URL.Hostname

Declaration:

gox
func (u URL) Hostname() string

Return the hostname without port.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.URL.Hostname()

URL.Port

Declaration:

gox
func (u URL) Port() string

Return the explicit port.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.URL.Port()

URL.Path

Declaration:

gox
func (u URL) Path() string

Returns the standard route.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.URL.Path()

URL.RawPath

Declaration:

gox
func (u URL) RawPath() string

Returns the original encoded route.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.URL.RawPath()

URL.QueryString

Declaration:

gox
func (u URL) QueryString() string

Returns the query string without analysis.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.URL.QueryString()

URL.Origin

Declaration:

gox
func (u URL) Origin() string

Returns schema and authority.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.URL.Origin()

Route

Declaration:

gox
type Route struct {
	Params Collection[string]
}

Route defines a public type of API.

Fields

FieldTypeDescription
ParamsCollection[string]Dynamic parameters of the route.

RouteInput

Declaration:

gox
type RouteInput struct {
	Matched       bool
	Original      string
	Target        string
	Pattern       string
	Method        string
	IsStatic      bool
	IsAction      bool
	IsClientAsset bool
	Params        Collection[string]
}

RouteInput defines a public type of API.

Fields

FieldTypeDescription
MatchedboolIt indicates if there was a coincidence.
OriginalstringOriginal route requested.
TargetstringDestination of the operation.
PatternstringPattern used for coincidence.
MethodstringHTTP method or Action name.
IsStaticboolIt indicates a static resource.
IsActionboolIt indicates an Action.
IsClientAssetboolIt indicates an asset of Client component.
ParamsCollection[string]Dynamic parameters of the route.

NewRoute

Declaration:

gox
func NewRoute(input RouteInput) Route

Build NewRoute.

Parameters

ParameterTypeDescription
inputRouteInputData used to build the value.

Returns

ReturnTypeDescription
valueRouteType value Route produced by the operation.

Usage syntax

gox
value := gox.NewRoute(gox.RouteInput{})

Route.IsMatched

Declaration:

gox
func (r Route) IsMatched() bool

It indicates whether a set-up rule produced the route.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Request.Route.IsMatched()

Route.Original

Declaration:

gox
func (r Route) Original() string

Returns the requested route before the resolution.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.Route.Original()

Route.Target

Declaration:

gox
func (r Route) Target() string

Returns the resolved internal destination.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.Route.Target()

Route.Pattern

Declaration:

gox
func (r Route) Pattern() string

Returns the pattern that produced the coincidence.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.Route.Pattern()

Route.Method

Declaration:

gox
func (r Route) Method() string

Returns the HTTP method or the solved method name.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := ctx.Request.Route.Method()

Route.IsStatic

Declaration:

gox
func (r Route) IsStatic() bool

It indicates if the destination is a static file.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Request.Route.IsStatic()

Route.IsAction

Declaration:

gox
func (r Route) IsAction() bool

It indicates if the fate is an Action.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Request.Route.IsAction()

Route.IsClientAsset

Declaration:

gox
func (r Route) IsClientAsset() bool

It indicates whether the destination belongs to a Client component.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := ctx.Request.Route.IsClientAsset()

Entry

Declaration:

gox
type Entry[T any] struct {
	Key   string
	Value []T
}

Entry defines a public type of API.

Fields

FieldTypeDescription
KeystringID key.
Value[]TValue stored.

Collection

Declaration:

gox
type Collection[T any] interface {
	Get(key string) (T, bool)
	GetAll(key string) ([]T, bool)
	Has(key string) bool
	IsEmpty() bool
	Count() int
	Keys() []string
	Values() map[string][]T
	Entries() []Entry[T]
}

Collection defines a public type of API.


NewCollection

Declaration:

gox
func NewCollection[T any](values map[string][]T) Collection[T]

Build NewCollection.

Parameters

ParameterTypeDescription
valuesmap[string][]TValues provided to the operation.

Returns

ReturnTypeDescription
valueCollection[T]Type value Collection[T] produced by the operation.

Usage syntax

gox
value := gox.NewCollection(value)

NewCollectionView

Declaration:

gox
func NewCollectionView[T any](values map[string][]T) Collection[T]

Build NewCollectionView.

Parameters

ParameterTypeDescription
valuesmap[string][]TValues provided to the operation.

Returns

ReturnTypeDescription
valueCollection[T]Type value Collection[T] produced by the operation.

Usage syntax

gox
value := gox.NewCollectionView(value)

Collection.Get

Declaration:

gox
func (c collection[T]) Get(key string) (T, bool)

It gets the first value associated with a key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Returns

ReturnTypeDescription
valueTType value T 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.Request.Headers.Get("key")

Collection.GetAll

Declaration:

gox
func (c collection[T]) GetAll(key string) ([]T, bool)

It gets all the values associated with a key.

Parameters

ParameterTypeDescription
keystringKey that identifies the value.

Returns

ReturnTypeDescription
value[]TResult 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.Request.Headers.GetAll("key")

Collection.Has

Declaration:

gox
func (c collection[T]) 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.Request.Headers.Has("key")

Collection.IsEmpty

Declaration:

gox
func (c collection[T]) 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.Request.Headers.IsEmpty()

Collection.Count

Declaration:

gox
func (c collection[T]) Count() int

Returns the number of keys or elements available.

Returns

ReturnTypeDescription
valueintType value int produced by the operation.

Usage syntax

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

Collection.Keys

Declaration:

gox
func (c collection[T]) 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.Request.Headers.Keys()

Collection.Values

Declaration:

gox
func (c collection[T]) Values() map[string][]T

Returns a copy of the values grouped by key.

Returns

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

Behavior

The returned map is a copy of the visible values.

Usage syntax

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

Collection.Entries

Declaration:

gox
func (c collection[T]) Entries() []Entry[T]

Return the tickets to the collection.

Returns

ReturnTypeDescription
value[]Entry[T]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.Request.Headers.Entries()

NewHeaders

Declaration:

gox
func NewHeaders(values map[string][]string) Collection[string]

Build NewHeaders.

Parameters

ParameterTypeDescription
valuesmap[string][]stringValues provided to the operation.

Returns

ReturnTypeDescription
valueCollection[string]Type value Collection[string] produced by the operation.

Usage syntax

gox
value := gox.NewHeaders(map[string][]string{})

NewCookies

Declaration:

gox
func NewCookies(values map[string]string) Collection[string]

Build NewCookies.

Parameters

ParameterTypeDescription
valuesmap[string]stringValues provided to the operation.

Returns

ReturnTypeDescription
valueCollection[string]Type value Collection[string] produced by the operation.

Usage syntax

gox
value := gox.NewCookies(map[string]string{})

See also

Next step

Continue with request body reading API.

Body