package urn
import "github.com/leodido/go-urn"
Index ¶
Examples ¶
Types ¶
type Machine ¶
Machine is the interface representing the FSM
func NewMachine ¶
func NewMachine() Machine
NewMachine creates a new FSM able to parse RFC 2141 strings.
type URN ¶
type URN struct { ID string // Namespace identifier SS string // Namespace specific string // contains filtered or unexported fields }
URN represents an Uniform Resource Name.
The general form represented is:
urn:<id>:<ss>
Details at https://tools.ietf.org/html/rfc2141.
func Parse ¶
Parse is responsible to create an URN instance from a byte array matching the correct URN syntax.
Code:
Output:Example¶
{
var uid = "URN:foo:a123,456"
if u, ok := urn.Parse([]byte(uid)); ok {
fmt.Println(u.ID)
fmt.Println(u.SS)
}
// Output: foo
// a123,456
}
foo
a123,456
func (*URN) Equal ¶
Equal checks the lexical equivalence of the current URN with another one.
Code:
Output:Example¶
{
var uid1 = "URN:foo:a123,456"
var uid2 = "URN:FOO:a123,456"
u1, ok := urn.Parse([]byte(uid1))
if !ok {
panic("invalid urn")
}
u2, ok := urn.Parse([]byte(uid2))
if !ok {
panic("invalid urn")
}
if u1.Equal(u2) {
fmt.Printf("%s equals %s", u1.String(), u2.String())
}
// Output: URN:foo:a123,456 equals URN:FOO:a123,456
}
URN:foo:a123,456 equals URN:FOO:a123,456
func (URN) MarshalJSON ¶
MarshalJSON marshals the URN to JSON string form (e.g. `"urn:oid:1.2.3.4"`).
Code:
Output:Example¶
{
var uid = "URN:foo:a123,456"
if u, ok := urn.Parse([]byte(uid)); ok {
json, err := u.MarshalJSON()
if err != nil {
panic("invalid urn")
}
fmt.Println(string(json))
}
// Output: "URN:foo:a123,456"
}
"URN:foo:a123,456"
func (*URN) Normalize ¶
Normalize turns the receiving URN into its norm version.
Which means: lowercase prefix, lowercase namespace identifier, and immutate namespace specific string chars (except <hex> tokens which are lowercased).
func (*URN) String ¶
String reassembles the URN into a valid URN string.
This requires both ID and SS fields to be non-empty. Otherwise it returns an empty string.
Default URN prefix is "urn".
func (*URN) UnmarshalJSON ¶
MarshalJSON unmarshals a URN from JSON string form (e.g. `"urn:oid:1.2.3.4"`).
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
tools | |
tools/removecomments | SPDX-License-Identifier: MIT |
- Version
- v1.2.2
- Published
- Feb 27, 2023
- Platform
- js/wasm
- Imports
- 3 packages
- Last checked
- now –
Tools for package owners.