Skip to content

Commit cf5ae53

Browse files
authored
refactor(urlkey): rename FromURL to Normalize (#35)
* Also updates related examples and tests.
2 parents 338eccb + 6a7e77a commit cf5ae53

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

internal/urlkeyer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ func (f URLKeyerFunc) URLKey(u *url.URL) string {
3232
return f(u)
3333
}
3434

35-
func NewURLKeyer() URLKeyer { return URLKeyerFunc(urlkey.FromURL) }
35+
func NewURLKeyer() URLKeyer { return URLKeyerFunc(urlkey.Normalize) }

pkg/urlkey/example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import (
2121
"github.com/bartventer/httpcache/pkg/urlkey"
2222
)
2323

24-
func ExampleFromURL() {
24+
func ExampleNormalize() {
2525
u, err := url.Parse(
2626
"https://example.com:8443/abc?query=param&another=value#fragment=part1&part2",
2727
)
2828
if err != nil {
2929
panic(err)
3030
}
31-
key := urlkey.FromURL(u)
31+
key := urlkey.Normalize(u)
3232
fmt.Println(key)
3333
// Output:
3434
// https://example.com:8443/abc?query=param&another=value

pkg/urlkey/urlkey.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ import (
3131
"github.com/bartventer/httpcache/internal/urlutil"
3232
)
3333

34-
// FromURL returns a normalized URL string suitable for use as a cache key.
34+
// Normalize returns a normalized URL string suitable for use as a cache key.
3535
//
3636
// It normalizes scheme/host case, default ports, dot-segments, and
3737
// percent-encoding (for path and query), and excludes fragments.
3838
//
3939
// For opaque URLs (u.Opaque != ""), the opaque value is returned unchanged.
40-
func FromURL(u *url.URL) string {
40+
func Normalize(u *url.URL) string {
4141
if u.Opaque != "" {
4242
return u.Opaque
4343
}

pkg/urlkey/urlkey_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ func TestFromURL(t *testing.T) {
8080
t.Errorf("url.Parse(%q) failed: %v", tt.raw, err)
8181
continue
8282
}
83-
testutil.AssertEqual(t, FromURL(u), tt.expected, "FromURL(%q)", tt.raw)
83+
testutil.AssertEqual(t, Normalize(u), tt.expected, "FromURL(%q)", tt.raw)
8484
}
8585
}

0 commit comments

Comments
 (0)