Skip to content

Commit

Permalink
Add urns.Schemes()
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed May 6, 2024
1 parent fb6f575 commit 6caa19e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions urns/schemes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions urns/urns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions urns/urns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6caa19e

Please sign in to comment.