diff --git a/dids/did/did.go b/dids/did/did.go index e1d8a05..cfd88a0 100644 --- a/dids/did/did.go +++ b/dids/did/did.go @@ -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 +} diff --git a/dids/did/did_test.go b/dids/did/did_test.go index 0adfef1..6919903 100644 --- a/dids/did/did_test.go +++ b/dids/did/did_test.go @@ -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 { @@ -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 -}