Skip to content

Commit

Permalink
feat(address): remove MustParseAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
saitofun committed Jul 9, 2024
1 parent f43bd25 commit 124e197
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 0 additions & 8 deletions address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

. "github.com/onsi/gomega"
"github.com/pkg/errors"
"github.com/xoctopus/x/misc/must"

. "github.com/xoctopus/datatypex"
)
Expand All @@ -21,15 +22,15 @@ 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",
Addr: NewAddress("avatar", "filename"),
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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 124e197

Please sign in to comment.