package urn
import "github.com/leodido/go-urn"
Index ¶
- Constants
- type Kind
- type Machine
- type Option
- type ParsingMode
- type SCIM
- func (s SCIM) MarshalJSON() ([]byte, error)
- func (s *SCIM) String() string
- func (s *SCIM) UnmarshalJSON(bytes []byte) error
- type URN
- func Parse(u []byte, options ...Option) (*URN, bool)
- 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
Types ¶
type Kind ¶
type Kind int
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 ¶
type Option func(Machine)
func WithParsingMode ¶
func WithParsingMode(mode ParsingMode) Option
type ParsingMode ¶
type ParsingMode int
const ( Default ParsingMode = iota RFC2141Only RFC7643Only RFC8141Only )
type SCIM ¶
type SCIM struct { Type scimschema.Type Name string Other string // contains filtered or unexported fields }
func (SCIM) MarshalJSON ¶
func (*SCIM) String ¶
func (*SCIM) UnmarshalJSON ¶
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).
Code:
Output: 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)
fmt.Println(u.SCIM())
}
// Output: foo
// a123,456
// <nil>
}
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
}
"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.
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) FComponent ¶
func (*URN) IsSCIM ¶
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) QComponent ¶
func (*URN) RComponent ¶
func (*URN) RFC ¶
func (*URN) SCIM ¶
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 ¶
UnmarshalJSON unmarshals a URN from JSON string form (e.g. `"urn:oid:1.2.3.4"`).
type URN8141 ¶
type URN8141 struct { *URN }
func (URN8141) MarshalJSON ¶
func (*URN8141) UnmarshalJSON ¶
Source Files ¶
kind.go machine.go options.go parsing_mode.go scim.go urn.go urn8141.go
Directories ¶
Path | Synopsis |
---|---|
scim | |
scim/schema |
- Version
- v1.4.0 (latest)
- Published
- Jan 31, 2024
- Platform
- windows/amd64
- Imports
- 4 packages
- Last checked
- now –
Tools for package owners.