diff --git a/urns/schemes.go b/urns/schemes.go index 706b043..ec26e77 100644 --- a/urns/schemes.go +++ b/urns/schemes.go @@ -47,9 +47,11 @@ func init() { } var schemes = map[string]*Scheme{} +var schemePrefixes = []string{} func register(s *Scheme) { schemes[s.Prefix] = s + schemePrefixes = append(schemePrefixes, s.Prefix) } type Scheme struct { diff --git a/urns/urns.go b/urns/urns.go index 276ad86..6a81732 100644 --- a/urns/urns.go +++ b/urns/urns.go @@ -17,6 +17,11 @@ func IsValidScheme(scheme string) bool { return valid } +// Schemes returns the valid URN schemes +func Schemes() []string { + return schemePrefixes +} + // URN represents a Universal Resource Name, we use this for contact identifiers like phone numbers etc.. type URN string diff --git a/urns/urns_test.go b/urns/urns_test.go index d35423d..b42ade2 100644 --- a/urns/urns_test.go +++ b/urns/urns_test.go @@ -12,6 +12,9 @@ import ( func TestIsValidScheme(t *testing.T) { assert.True(t, urns.IsValidScheme("tel")) assert.False(t, urns.IsValidScheme("xyz")) + + assert.Len(t, urns.Schemes(), 20) + assert.Equal(t, "discord", urns.Schemes()[0]) } func TestURNProperties(t *testing.T) {