Documentation ¶
Index ¶
- Constants
- type Kind
- type Machine
- type Option
- type ParsingMode
- type SCIM
- type URN
- func (u *URN) Equal(x *URN) bool
- func (u *URN) FComponent() string
- func (u *URN) IsSCIM() bool
- func (u URN) MarshalJSON() ([]byte, error)
- func (u *URN) Normalize() *URN
- func (u *URN) QComponent() string
- func (u *URN) RComponent() string
- func (u *URN) RFC() Kind
- func (u *URN) SCIM() *SCIM
- func (u *URN) String() string
- func (u *URN) UnmarshalJSON(bytes []byte) error
- type URN8141
Examples ¶
Constants ¶
const DefaultParsingMode = RFC2141Only
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Machine ¶
type Machine interface { Error() error Parse(input []byte) (*URN, error) WithParsingMode(ParsingMode) }
Machine is the interface representing the FSM
func NewMachine ¶
NewMachine creates a new FSM able to parse RFC 2141 strings.
type Option ¶ added in v1.3.0
type Option func(Machine)
func WithParsingMode ¶ added in v1.3.0
func WithParsingMode(mode ParsingMode) Option
type ParsingMode ¶ added in v1.3.0
type ParsingMode int
const ( Default ParsingMode = iota RFC2141Only RFC7643Only RFC8141Only )
type SCIM ¶ added in v1.3.0
type SCIM struct { Type scimschema.Type Name string Other string // contains filtered or unexported fields }
func (SCIM) MarshalJSON ¶ added in v1.4.0
func (*SCIM) UnmarshalJSON ¶ added in v1.4.0
type URN ¶
type URN struct { ID string // Namespace identifier (NID) SS string // Namespace specific string (NSS) // 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 (RFC 2141).
Example ¶
var uid = "URN:foo:a123,456" if u, ok := urn.Parse([]byte(uid)); ok { fmt.Println(u.ID) fmt.Println(u.SS) fmt.Println(u.SCIM()) }
Output: foo a123,456 <nil>
Example (Scim) ¶
input := "urn:ietf:params:scim:api:messages:2.0:ListResponse" u, ok := urn.Parse([]byte(input), urn.WithParsingMode(urn.RFC7643Only)) if !ok { panic("invalid SCIM urn") } data, err := u.MarshalJSON() if err != nil { panic("couldn't marshal") } fmt.Println(string(data)) fmt.Println(u.IsSCIM()) scim := u.SCIM() fmt.Println(scim.Type.String()) fmt.Println(scim.Name) fmt.Println(scim.Other)
Output: "urn:ietf:params:scim:api:messages:2.0:ListResponse" true api messages 2.0:ListResponse
func (*URN) Equal ¶
Equal checks the lexical equivalence of the current URN with another one.
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
func (*URN) FComponent ¶ added in v1.4.0
func (URN) MarshalJSON ¶ added in v1.2.1
MarshalJSON marshals the URN to JSON string form (e.g. `"urn:oid:1.2.3.4"`).
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"
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) QComponent ¶ added in v1.4.0
func (*URN) RComponent ¶ added in v1.4.0
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 ¶ added in v1.2.1
UnmarshalJSON unmarshals a URN from JSON string form (e.g. `"urn:oid:1.2.3.4"`).