Skip to content

Commit

Permalink
DID MustParse (#162)
Browse files Browse the repository at this point in the history
* DID MustParse

* lint
  • Loading branch information
tomdaffurn authored Aug 2, 2024
1 parent d927bc2 commit da214f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
9 changes: 9 additions & 0 deletions dids/did/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,12 @@ func Parse(input string) (DID, error) {

return did, nil
}

// MustParse parses a DID URI with Parse, and panics on error
func MustParse(input string) DID {
did, err := Parse(input)
if err != nil {
panic(err)
}
return did
}
20 changes: 6 additions & 14 deletions dids/did/did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,27 @@ func TestDID_ScanValueRoundtrip(t *testing.T) {
}{
{
raw: "did:example:123456789abcdefghi",
object: MustParse("did:example:123456789abcdefghi"),
object: did.MustParse("did:example:123456789abcdefghi"),
},
{
raw: "did:example:123456789abcdefghi;foo=bar;baz=qux",
object: MustParse("did:example:123456789abcdefghi;foo=bar;baz=qux"),
object: did.MustParse("did:example:123456789abcdefghi;foo=bar;baz=qux"),
},
{
raw: "did:example:123456789abcdefghi?foo=bar&baz=qux",
object: MustParse("did:example:123456789abcdefghi?foo=bar&baz=qux"),
object: did.MustParse("did:example:123456789abcdefghi?foo=bar&baz=qux"),
},
{
raw: "did:example:123456789abcdefghi#keys-1",
object: MustParse("did:example:123456789abcdefghi#keys-1"),
object: did.MustParse("did:example:123456789abcdefghi#keys-1"),
},
{
raw: "did:example:123456789abcdefghi?foo=bar&baz=qux#keys-1",
object: MustParse("did:example:123456789abcdefghi?foo=bar&baz=qux#keys-1"),
object: did.MustParse("did:example:123456789abcdefghi?foo=bar&baz=qux#keys-1"),
},
{
raw: "did:example:123456789abcdefghi;foo=bar;baz=qux?foo=bar&baz=qux#keys-1",
object: MustParse("did:example:123456789abcdefghi;foo=bar;baz=qux?foo=bar&baz=qux#keys-1"),
object: did.MustParse("did:example:123456789abcdefghi;foo=bar;baz=qux?foo=bar&baz=qux#keys-1"),
},
}
for _, tt := range tests {
Expand All @@ -163,11 +163,3 @@ func TestDID_ScanValueRoundtrip(t *testing.T) {
})
}
}

func MustParse(input string) did.DID {
d, err := did.Parse(input)
if err != nil {
panic(err)
}
return d
}

0 comments on commit da214f6

Please sign in to comment.