Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
Filter specifies field name to apply filtering to, a predicate expressed in textual form, the package does not know specific filtering syntax 'filter[createdAt]=lt:2015-01-01' = Filter{FieldName: "createdAt", Predicate: "lt:2015-01-01"}
type Include ¶
Include determines resources that should be included in a response 'include=comments.author' = Include{Relation: "comments", Includes: []Include{{Relation: "author"}}}
type Page ¶
Page is pagination parameters 'page[size]=10&page[number]=2' = Page{Size: "10", Number: "2"} limit, offset, cursor are populated as well, the package is unaware of the pagination implementation
type Query ¶
type Query struct {
Includes []Include
Fields ResourceFields
Sort []Sort
Filters []Filter
Page *Page
Values Values
}
Query contains all parameters read from the query string
func ParseQuery ¶
ParseQuery parses a string and returns a structure filled with the corresponding values Query is expected to be a list of key=value settings separated by ampersands or semicolons. A setting without an equals sign is interpreted as a key set to an empty value. Query can contain nested keys, which are defined by square brackets, for example: page[size], page[number]
type Request ¶
type Request struct {
Resource Resource
RelationshipType string
RelatedResourceType string
Query *Query
}
Request represents the result of parsing the path and query string
func ParseRequest ¶
ParseRequest parses the string into a path and a query, which are expected to be separated by a question mark '?' the path is parsed as follows: "/articles" - article list request "/articles/42" - request of article with id 42 "/articles/42/author" - request of an author related to the article with id 42 "/article/42/relationships/author" - relationships request
see https://jsonapi.org/format/#document-resource-object-relationships
for the query part description see "ParseQuery"
func (*Request) IsRelatedResourceRequest ¶
func (*Request) IsRelationshipRequest ¶
type Resource ¶
Resource determines the requested resource or the type of the resource ID might be empty string in case if a list of the resource type is requested
type ResourceFields ¶
ResourceFields contains a list of requested fields for the resources 'fields[articles]=title,body' = ResourceFields{"articles": {"title", "body"}}
func (ResourceFields) FieldsByResource ¶
func (r ResourceFields) FieldsByResource(resource string) (fields []string, ok bool)
FieldsByResource retrieves a list of fields by the given resource the second return value indicates if the list is set
type Sort ¶
Sort indicates the field by which the sorting should be performed and the sorting direction
type Values ¶
Values maps a string top key to a list of values and nested keys.
func ParseValues ¶
ParseValues parses a string and returns a structure filled with the corresponding values query string is expected to be a list of key=value settings separated by ampersands or semicolons. A setting without an equals sign is interpreted as a key set to an empty value. Query can contain nested keys, which are defined by square brackets, for example: page[size], page[number]
func (Values) Get ¶
Get retrieves the first value associated with the top key which contains all the nested keys. If there are no values associated with the combination, Get returns the empty string. To access multiple values, use the map directly.
func (Values) GetExist ¶
GetExist retrieves the first value associated with the top key which contains all the nested keys. Second return value determines whether the value is exist. If there are no values associated with the combination, then GetExist returns the empty string. To access multiple values, use the map directly.