rfc3986

package module
v0.0.0-...-d40467d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2025 License: MIT Imports: 4 Imported by: 4

README

go-rfc3986

Package rfc3986 is an implementation of (parts of) IETF RFC-3986, for the Go programming language.

Uniform Resource Identifier (URI): Generic Syntax (January 2005)
https://datatracker.ietf.org/doc/html/rfc3986

Definition in IETF RFC-3986 are referred to in a numer of other IETF RFCs. And thus, tools provided in this package can also be helpful in implementing this IETF RFCs, too.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-rfc3986

GoDoc

Import

To import package rfc3986 use import code like the follownig:

import "github.com/reiver/go-rfc3986"

Installation

To install package rfc3986 do the following:

GOPROXY=direct go get https://github.com/reiver/go-rfc3986

Author

Package rfc3986 was written by Charles Iliya Krempeaux

Documentation

Index

Constants

View Source
const SchemeTerminator = ':'

Variables

This section is empty.

Functions

func DecodePctEncoded

func DecodePctEncoded(b2 byte, b3 byte) (byte, error)

DecodePctEncoded decodes the 2nd and 3rd byte of an IETF RFC-3986 'pct-encoded'. (The 1st byte of an IETF RFC-3986 'pct-encoded' is a percent-symbol (i.e., '%'), so we don't include it in the parameters.)

For example, this:

b, err := rfc3986.DecodePctEncoded('2', 'F')

Would return:

'/'

func HasPrefixPctEncoded

func HasPrefixPctEncoded(str string) bool

HasPrefixPctEncoded returns true if what is at the beginning of the string is 'pct-encoded' as defined by IETF RFC-3986.

For example, any of these would return 'true':

"%2Fdir"

"%7Ejoeblow"

And, for example, any of these would return 'false':

"Hello world!"

"dir%2F"

"joeblow%40example.com"

'pct-encoded' is defined by IETF RFC-3986 as follows:

pct-encoded = "%" HEXDIG HEXDIG

Where 'HEXDIG' is defined in IETF RFC-2234 as:

HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"

DIGIT  = %x30-39
       ; 0-9

func IsAlpha

func IsAlpha(r rune) bool

func IsAlphaNum

func IsAlphaNum(r rune) bool

func IsDigit

func IsDigit(r rune) bool

func IsGenDelim

func IsGenDelim(r rune) bool

IsGenDelim returns true if the value of 'r' matches 'sub-delims' as defined in IETF RFC-3986:

gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"

func IsHexDig

func IsHexDig(r rune) bool

func IsPctEncodedPrefix

func IsPctEncodedPrefix(r rune) bool

IsPctEncodedPrefix return 'true' if the rune is the 'pct-encoded' prefix character (i.e., if it is '%'), and returns 'false' otherwise.

Note, to determine if a string begins with a 'pct-encoded' instead use HasPrefixPctEncoded.

func IsReserved

func IsReserved(r rune) bool

IsReserved returns true if value of 'r' matches 'reserved' as defined in IETF RFC-3986:

reserved    = gen-delims / sub-delims

gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"

sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="

func IsSubDelim

func IsSubDelim(r rune) bool

IsSubDelim returns true if the value of 'r' matches 'sub-delims' as defined in IETF RFC-3986:

sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="

func IsUnreserved

func IsUnreserved(r rune) bool

IsUnreserved returns true if the value of 'r' matches 'unreserved' as defined in IETF RFC-3986:

unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"

func PeekPrefixFragment

func PeekPrefixFragment(str string) (fragment string, n int, found bool)

PeekPrefixFragment looks at `str` and if it starts (and ends) with a fragment, as defined by IETF RFC-3986, then it returns it (without the '#' prefix).

PeekPrefixFragment expects `str` to start with a '#', but the '#' is not returns as part of `fragment`. `n` includes the length of '#'.

IETF RFC-3986 defines 'fragment' as follows:

A fragment identifier component is indicated by
the presence of a number sign ("#") character and
terminated by the end of the URI.

fragment = *( pchar / "/" / "?" )

func PeekPrefixPChar

func PeekPrefixPChar(str string) (byte, int, bool)

PeekPrefixPChar peeks a string, checks to see if it starts with a 'pchar' (as defined in IETF RFC-3986), and returns it if it does.

'pchar' is defined in IETF RFC-3986 as:

pchar = unreserved / pct-encoded / sub-delims / ":" / "@"

func PeekPrefixPctEncoded

func PeekPrefixPctEncoded(str string) (byte, int, bool)

func PeekPrefixScheme

func PeekPrefixScheme(str string) (scheme string, n int, found bool)

PeekPrefixScheme peeks and returns the 'scheme' as defined by IETF RFC-3986:

scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )

ALPHA  = %41-%5A / %61-%7A

DIGIT  = %30-%39

func PeekPrefixSubDelims

func PeekPrefixSubDelims(str string) (byte, int, bool)

func PeekPrefixUnreserved

func PeekPrefixUnreserved(str string) (byte, int, bool)

func ReadPctEncodedByte

func ReadPctEncodedByte(reader io.Reader) (byte, error)

func ReadScheme

func ReadScheme(reader io.Reader) (string, error)

ReadScheme reads and return the 'scheme' as defined by IETF RFC-3986:

scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )

ALPHA  = %41-%5A / %61-%7A

DIGIT  = %30-%39

Although ReadScheme reads the colon (":") it does not return it as part of the scheme.

func ValidateScheme

func ValidateScheme(scheme string) error

func WritePctEncodedByte

func WritePctEncodedByte(writer io.Writer, b byte) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL