Skip to content

Commit

Permalink
Do not export Attrs.Encode() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbub committed Oct 21, 2021
1 parent f411309 commit 9881204
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.1.0

- Pass `context.Context` to `Comment` method.
- Do not export `Attrs.Encode()` method.

## v0.0.1

- Initial release.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

Go implementation of https://google.github.io/sqlcommenter/.

Public API is not stable, expect breaking changes.

## Usage with pgx stdlib driver

```go
Expand Down
14 changes: 7 additions & 7 deletions attrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ type Attr struct {

type Attrs map[string]string

func (a Attrs) Encode() string {
func (a Attrs) Update(other Attrs) {
for k, v := range other {
a[k] = v
}
}

func (a Attrs) encode() string {
total := len(a)
keys := make([]string, 0, total)
for k := range a {
Expand All @@ -44,12 +50,6 @@ func (a Attrs) Encode() string {
return b.String()
}

func (a Attrs) Update(other Attrs) {
for k, v := range other {
a[k] = v
}
}

func encodeKey(k string) string {
return url.QueryEscape(k)
}
Expand Down
17 changes: 16 additions & 1 deletion attrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,25 @@ func TestAttrsEncode(t *testing.T) {

for _, cs := range cases {
t.Run(cs.name, func(t *testing.T) {
got := cs.attrs.Encode()
got := cs.attrs.encode()
if want := cs.want; want != got {
t.Errorf("got '%v', want '%v'", got, want)
}
})
}
}

func BenchmarkAttrsEncode(b *testing.B) {
b.ReportAllocs()
b.SetBytes(2)

attrs := Attrs(map[string]string{
"key": "value",
"2key": "value 33",
"key3": "44 value",
})

for i := 0; i < b.N; i++ {
attrs.encode()
}
}

0 comments on commit 9881204

Please sign in to comment.