Skip to content

Commit

Permalink
gurl
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Feb 7, 2025
1 parent b6a238a commit ceac55e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions util/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Builder struct {
query map[string]string
holders []string
port string
err error
}

func NewBuilder() *Builder {
Expand All @@ -25,6 +26,15 @@ func (s *Builder) HTTP() *Builder {
return s
}

func (s *Builder) Parse(ref string) (b *Builder) {
s.URL, s.err = s.URL.Parse(ref)
return s
}

func (s *Builder) Error() error {
return s.err
}

func (s *Builder) String() string {
if s.URL.Scheme == "" {
s.HTTP()
Expand Down
5 changes: 5 additions & 0 deletions util/url/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func TestURLBuilder_Query(t *testing.T) {
assert.Equal(t, "http://a.com:88/", link.String())
link = NewBuilder().Host("a.com").Port("88").SetQuery("a", "1")
assert.Equal(t, "http://a.com:88/?a=1", link.String())
link = NewBuilder().Parse("http://a.com:88/?a=1")
assert.Equal(t, "http://a.com:88/?a=1", link.String())
assert.Nil(t, link.Error())
link = NewBuilder().Parse("http://a.com:abc/?a=1")
assert.NotNil(t, link.Error())
}

func TestGetConcatChar(t *testing.T) {
Expand Down

0 comments on commit ceac55e

Please sign in to comment.