package httpsfvimport ()// isExtendedTchar checks if c is a valid token character as defined in the spec.func isExtendedTchar( byte) bool {ifisAlpha() || isDigit() {returntrue }switch {case'!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~', ':', '/':returntrue }returnfalse}// ErrInvalidTokenFormat is returned when a token format is invalid.varErrInvalidTokenFormat = errors.New("invalid token format")// Token represents a token as defined in// https://httpwg.org/specs/rfc9651.html#token.// A specific type is used to distinguish tokens from strings.typeTokenstring// marshalSFV serializes as defined in// https://httpwg.org/specs/rfc9651.html#ser-token.func ( Token) ( io.StringWriter) error {iflen() == 0 {returnfmt.Errorf("a token cannot be empty: %w", ErrInvalidTokenFormat) }if !isAlpha([0]) && [0] != '*' {returnfmt.Errorf("a token must start with an alpha character or *: %w", ErrInvalidTokenFormat) }for := 1; < len(); ++ {if !isExtendedTchar([]) {returnfmt.Errorf("the character %c isn't allowed in a token: %w", [], ErrInvalidTokenFormat) } } , := .WriteString(string())return}// parseToken parses as defined in// https://httpwg.org/specs/rfc9651.html#parse-token.func parseToken( *scanner) (Token, error) {if .eof() || (!isAlpha(.data[.off]) && .data[.off] != '*') {return"", &UnmarshalError{.off, ErrInvalidTokenFormat} } := .off .off++for !.eof() {if !isExtendedTchar(.data[.off]) {break } .off++ }returnToken(.data[:.off]), 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.