package httpsfv

Import Path
	github.com/dunglas/httpsfv (on go.dev)

Dependency Relation
	imports 12 packages, and imported by one package

Involved Source Files bareitem.go binary.go boolean.go date.go decimal.go decode.go dictionary.go displaystring.go Package httpsfv implements serializing and parsing of Structured Field Values for HTTP as defined in RFC 9651. Structured Field Values are either lists, dictionaries or items. Dedicated types are provided for all of them. Dedicated types are also used for tokens, parameters and inner lists. Other values are stored in native types: int64, for integers float64, for decimals string, for strings byte[], for byte sequences bool, for booleans The specification is available at https://httpwg.org/specs/rfc9651.html. innerlist.go integer.go item.go key.go list.go member.go params.go string.go token.go utils.go
Code Examples { p := List{NewItem("/member/*/author"), NewItem("/member/*/comments")} v, err := Marshal(p) if err != nil { log.Fatalln("error: ", err) } h := http.Header{} h.Set("Preload", v) b := new(bytes.Buffer) _ = h.Write(b) fmt.Println(b.String()) } { h := http.Header{} h.Add("Preload", `"/member/*/author", "/member/*/comments"`) v, err := UnmarshalList(h["Preload"]) if err != nil { log.Fatalln("error: ", err) } fmt.Println("authors selector: ", v[0].(Item).Value) fmt.Println("comments selector: ", v[1].(Item).Value) }
Package-Level Type Names (total 10)
/* sort by: | */
Dictionary is an ordered map of name-value pairs. See https://httpwg.org/specs/rfc9651.html#dictionary Values can be: * Item (Section 3.3.) * Inner List (Section 3.1.1.) Add appends a new member to the ordered list. Del removes a member from the ordered list. Get retrieves a member. Names retrieves the list of member names in the appropriate order. *Dictionary : StructuredFieldValue func NewDictionary() *Dictionary func UnmarshalDictionary(v []string) (*Dictionary, error)
DisplayString : StructuredFieldValue
InnerList represents an inner list as defined in https://httpwg.org/specs/rfc9651.html#inner-list. Items []Item Params *Params InnerList : Member InnerList : StructuredFieldValue
Item is a bare value and associated parameters. See https://httpwg.org/specs/rfc9651.html#item. Params *Params Value interface{} Item : Member Item : StructuredFieldValue func NewItem(v interface{}) Item func UnmarshalItem(v []string) (Item, error)
List contains items an inner lists. See https://httpwg.org/specs/rfc9651.html#list List : StructuredFieldValue func UnmarshalList(v []string) (List, error)
Member is a marker interface for members of dictionaries and lists. See https://httpwg.org/specs/rfc9651.html#list. InnerList Item Member : StructuredFieldValue func (*Dictionary).Get(k string) (Member, bool) func (*Dictionary).Add(k string, v Member)
Params are an ordered map of key-value pairs that are associated with an item or an inner list. See https://httpwg.org/specs/rfc9651.html#param. Add appends a new parameter to the ordered list. If the key already exists, overwrite its value. Del removes a parameter from the ordered list. Get retrieves a parameter. Names retrieves the list of parameter names in the appropriate order. *Params : StructuredFieldValue func NewParams() *Params
StructuredFieldValue represents a List, a Dictionary or an Item. *Dictionary DisplayString InnerList Item List Member (interface) *Params func Marshal(v StructuredFieldValue) (string, error)
Token represents a token as defined in https://httpwg.org/specs/rfc9651.html#token. A specific type is used to distinguish tokens from strings.
UnmarshalError contains the underlying parsing error and the position at which it occurred. (*UnmarshalError) Error() string (*UnmarshalError) Unwrap() error *UnmarshalError : error *UnmarshalError : golang.org/x/xerrors.Wrapper
Package-Level Functions (total 7)
Marshal returns the HTTP Structured Value serialization of v as defined in https://httpwg.org/specs/rfc9651.html#text-serialize. v must be a List, a Dictionary, an Item or an InnerList.
NewDictionary creates a new ordered map.
NewItem returns a new Item.
NewParams creates a new ordered map.
UnmarshalDictionary parses a dictionary as defined in https://httpwg.org/specs/rfc9651.html#parse-dictionary.
UnmarshalItem parses an item as defined in https://httpwg.org/specs/rfc9651.html#parse-item.
UnmarshalList parses a list as defined in https://httpwg.org/specs/rfc9651.html#parse-list.
Package-Level Variables (total 20)
ErrInvalidBareItem is returned when a bare item is invalid.
ErrInvalidBinaryFormat is returned when the binary format is invalid.
ErrInvalidBooleanFormat is returned when a boolean format is invalid.
ErrInvalidDecimal is returned when a decimal is invalid.
ErrInvalidDecimalFormat is returned when the decimal format is invalid.
ErrInvalidDictionaryFormat is returned when a dictionary value is invalid.
ErrInvalidInnerListFormat is returned when an inner list format is invalid.
ErrInvalidKeyFormat is returned when the format of a parameter or dictionary key is invalid.
ErrInvalidListFormat is returned when the format of a list is invalid.
ErrInvalidParameterFormat is returned when the format of a parameter is invalid.
ErrInvalidParameterValue is returned when a parameter key is invalid.
ErrInvalidStringFormat is returned when a string format is invalid.
ErrInvalidTokenFormat is returned when a token format is invalid.
ErrMissingParameters is returned when the Params structure is missing from the element.
ErrNotDigit is returned when a character should be a digit but isn't.
ErrNumberOutOfRange is returned when the number is too large according to the specification.
ErrUnexpectedEndOfString is returned when the end of string is unexpected.
ErrUnrecognizedCharacter is returned when an unrecognized character in encountered.