rfc8141

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

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 3 Imported by: 0

README

go-rfc8141

Package rfc8141 is a low-level implementation of IETF RFC-8141 "URNs (Uniform Resource Names)", for the Go programming language.

For a higher-level implementation of URNs (Uniform Resource Names), instead use https://github.com/reiver/go-urn

Documention

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

GoDoc

Import

To import package rfc8141 use import code like the following:

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

Installation

To install package rfc8141 do the following:

GOPROXY=direct go get github.com/reiver/go-rfc8141

Author

Package rfc8141 was written by Charles Iliya Krempeaux

Documentation

Index

Constants

View Source
const Scheme = "urn"

Scheme is the URI scheme of a URN.

The URI scheme of a URN is always "urn".

Variables

View Source
var NIDs = []string{
	"3gpp",
	"3gpp2",
	"adid",
	"alert",
	"bbf",
	"broadband-forum-org",
	"c2pa",
	"cablelabs",
	"ccsds",
	"cdx",
	"cgi",
	"clei",
	"csa",
	"cta",
	"ddi",
	"dev",
	"dgiwg",
	"doi",
	"dslforum-org",
	"dvb",
	"ebu",
	"eic",
	"eidr",
	"epc",
	"epcglobal",
	"etsi",
	"eurosystem",
	"example",
	"fdc",
	"fipa",
	"gdst",
	"geant",
	"globus",
	"gsma",
	"gvat",
	"hbbtv",
	"ieee",
	"ietf",
	"iptc",
	"isan",
	"isbn",
	"iso",
	"issn",
	"itu",
	"ivis",
	"knx",
	"lei",
	"lex",
	"liberty",
	"mace",
	"mef",
	"meta",
	"mpeg",
	"mrn",
	"nan",
	"nato",
	"nbn",
	"nena",
	"newsml",
	"nfc",
	"nzl",
	"oasis",
	"ogc",
	"ogf",
	"oid",
	"oipf",
	"oma",
	"onem2m",
	"onf",
	"pin",
	"pno",
	"publicid",
	"pwid",
	"reso",
	"s1000d",
	"schac",
	"service",
	"smpte",
	"stalwart",
	"swift",
	"thread",
	"tva",
	"uci",
	"ucode",
	"uic",
	"uuid",
	"web3d",
	"wmo",
	"xmlorg",
	"xmpp",
}

NIDs is a list of registered URN NIDs, taken from:

https://www.iana.org/assignments/urn-namespaces/urn-namespaces.xhtml

... when it was last updated on:

2025-07-02

Functions

func IsAlphaNum

func IsAlphaNum(r rune) bool

IsAlphaNum return 'true' if the rune is an "alphanum" as defined by IETF RFC-8141, and returns 'false' otherwise.

IETF RFC-8141 imports the definition of "alphanum" from IETF RFC-3986.

For example:

result := rfc8141.IsAlphaNum("E")
// result == true

And also, for example:

result := rfc8141.IsAlphaNum("-")
// result == false

func NormalizeNID

func NormalizeNID(nid string) string

NormalizeNID returns the normalized form of an NID (Namespace Identifier).

From IETF RFC-8141:

"NIDs are case insensitive (e.g., "ISBN" and "isbn" are equivalent)."

Normalization lower-cases chracter 'A' through 'Z' to 'a' through 'z'.

func PeekPrefixFComponent

func PeekPrefixFComponent(str string) (fcomponent string, n int, found bool)

PeekPrefixFComponent 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).

PeekPrefixFComponent 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 PeekPrefixNID

func PeekPrefixNID(str string) (n int, found bool)

PeekPrefixNID looks to see if `str` begins with an NID (Namespace Identifier), and if it does, then return its length.

IETF RFC-8141 defines an NID (Namespace Identifier) as follows:

NID = (alphanum) 0*30(ldh) (alphanum)

ldh = alphanum / "-"

func PeekPrefixNSS

func PeekPrefixNSS(str string) (nss string, n int, found bool)

PeekPrefixNSS looks to see if `str` begins with an NSS (Namespace Specific String), and if it does, then returns the decoded NSS (Namespace Specific String) its original (encoded) length.

IETF RFC-8141 defines an NSS (Namespace Specific String) as follows:

NSS = pchar *(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 PeekPrefixQComponent

func PeekPrefixQComponent(str string) (rcomponent string, n int, found bool)

PeekPrefixQComponent looks to see if `str` begins with an q-component (without the "?=" prefix), and if it does, then returns the decoded q-component and its original (encoded) length.

Notet that PeekPrefixQComponent expectd the "?+" to be there.

IETF RFC-8141 defines an q-component as follows:

rq-components = [ "?+" r-component ]
                [ "?=" q-component ]

q-component   = pchar *( pchar / "/" / "?" )

func PeekPrefixRComponent

func PeekPrefixRComponent(str string) (rcomponent string, n int, found bool)

PeekPrefixRComponent looks to see if `str` begins with an r-component (without the "?+" prefix), and if it does, then returns the decoded r-component and its original (encoded) length.

Notet that PeekPrefixRComponent expectd the "?+" to be there.

IETF RFC-8141 defines an r-component as follows:

rq-components = [ "?+" r-component ]
                [ "?=" q-component ]

r-component   = pchar *( pchar / "/" / "?" )

Types

This section is empty.

Jump to

Keyboard shortcuts

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