From 124e1973c1c303e0d3ee7dd5809f2572fbd974ef Mon Sep 17 00:00:00 2001 From: sincos Date: Tue, 9 Jul 2024 23:24:40 +0800 Subject: [PATCH] feat(address): remove MustParseAddress --- address.go | 8 -------- address_test.go | 9 +++++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/address.go b/address.go index 4a3ea1d..c7d01de 100644 --- a/address.go +++ b/address.go @@ -30,14 +30,6 @@ func ParseAddress(text string) (*Address, error) { return a, nil } -func MustParseAddress(text string) *Address { - v, err := ParseAddress(text) - if err != nil { - panic(err) - } - return v -} - func NewAddress(group, filename string) *Address { ext := strings.TrimPrefix(filepath.Ext(filename), ".") key := strings.TrimSuffix(filename, "."+ext) diff --git a/address_test.go b/address_test.go index bbd13f5..daf0f9d 100644 --- a/address_test.go +++ b/address_test.go @@ -5,6 +5,7 @@ import ( . "github.com/onsi/gomega" "github.com/pkg/errors" + "github.com/xoctopus/x/misc/must" . "github.com/xoctopus/datatypex" ) @@ -21,7 +22,7 @@ func TestAddress_MarshalText(t *testing.T) { Expect: "asset://avatar/filename.png", }, { Name: "HttpFileURI", - Addr: MustParseAddress("https://demo.com/avatar/filename.png"), + Addr: must.NoErrorV(ParseAddress("https://demo.com/avatar/filename.png")), Expect: "https://demo.com/avatar/filename.png", }, { Name: "WithoutExtension", @@ -29,7 +30,7 @@ func TestAddress_MarshalText(t *testing.T) { Expect: "asset://avatar/filename", }, { Name: "LocalFile", - Addr: MustParseAddress("file:///AbsPath/To/Your/Local/File.ext"), + Addr: must.NoErrorV(ParseAddress("file:///AbsPath/To/Your/Local/File.ext")), Expect: "file:///AbsPath/To/Your/Local/File.ext", }, { Name: "Empty", @@ -64,11 +65,11 @@ func TestAddress_UnmarshalText(t *testing.T) { }, { Name: "HttpFileURL", Input: "https://group.com/avatar/filename.png", - OutVal: MustParseAddress("https://group.com/avatar/filename.png"), + OutVal: must.NoErrorV(ParseAddress("https://group.com/avatar/filename.png")), }, { Name: "LocalFile", Input: "file:///AbsPath/To/Your/Local/File.ext", - OutVal: MustParseAddress("file:///AbsPath/To/Your/Local/File.ext"), + OutVal: must.NoErrorV(ParseAddress("file:///AbsPath/To/Your/Local/File.ext")), }, { Name: "InvalidURI", Input: "http://foo.com/ctl\x7f",