package httpsfvimport ()// 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.typeParamsstruct { names []string values map[string]interface{}}// ErrInvalidParameterFormat is returned when the format of a parameter is invalid.varErrInvalidParameterFormat = errors.New("invalid parameter format")// ErrInvalidParameterValue is returned when a parameter key is invalid.varErrInvalidParameterValue = errors.New("invalid parameter value")// ErrMissingParameters is returned when the Params structure is missing from the element.varErrMissingParameters = errors.New("missing parameters")// NewParams creates a new ordered map.func () *Params { := Params{} .names = []string{} .values = map[string]interface{}{}return &}// Get retrieves a parameter.func ( *Params) ( string) (interface{}, bool) { , := .values[]return , }// Add appends a new parameter to the ordered list.// If the key already exists, overwrite its value.func ( *Params) ( string, interface{}) {assertBareItem()if , := .values[]; ! { .names = append(.names, ) } .values[] = }// Del removes a parameter from the ordered list.func ( *Params) ( string) bool {if , := .values[]; ! {returnfalse }for , := range .names {if == { .names = append(.names[:], .names[+1:]...)break } }delete(.values, )returntrue}// Names retrieves the list of parameter names in the appropriate order.func ( *Params) () []string {return .names}// marshalSFV serializes as defined in// https://httpwg.org/specs/rfc9651.html#ser-params.func ( *Params) ( *strings.Builder) error {if == nil {returnErrMissingParameters }for , := range .names {if := .WriteByte(';'); != nil {return }if := marshalKey(, ); != nil {return } := .values[]if == true {continue }if := .WriteByte('='); != nil {return }if := marshalBareItem(, ); != nil {return } }returnnil}// parseParams parses as defined in// https://httpwg.org/specs/rfc9651.html#parse-param.func parseParams( *scanner) (*Params, error) { := NewParams()for !.eof() {if .data[.off] != ';' {break } .off++ .scanWhileSp() , := parseKey()if != nil {returnnil, }varinterface{}if !.eof() && .data[.off] == '=' { .off++ , = parseBareItem()if != nil {returnnil, } } else { = true } .Add(, ) }return , nil}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.