Skip to content

Commit

Permalink
refactor(helpers): rename helper to helpers (#159)
Browse files Browse the repository at this point in the history
Signed-off-by: Flc゛ <[email protected]>
  • Loading branch information
flc1125 authored Mar 16, 2024
1 parent bded6bb commit f07fd25
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cache/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/go-kratos-ecosystem/components/v2/helper"
"github.com/go-kratos-ecosystem/components/v2/helpers"
)

type Repository interface {
Expand Down Expand Up @@ -79,7 +79,7 @@ func (r *repository) Remember(
return err
}

return helper.Scan(v, dest)
return helpers.Scan(v, dest)
}

return r.Get(ctx, key, dest)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion helper/helper.go → helpers/helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helper
package helpers

import (
"encoding/json"
Expand Down
34 changes: 17 additions & 17 deletions helper/helper_test.go → helpers/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helper
package helpers

import (
"context"
Expand Down Expand Up @@ -122,8 +122,8 @@ func TestWhen(t *testing.T) {
}

func TestPipe(t *testing.T) {
// chain functions
chain := Pipe(
// pipe functions
pipe := Pipe(
func(s string) string {
return s + "1"
},
Expand All @@ -135,10 +135,10 @@ func TestPipe(t *testing.T) {
},
)

assert.Equal(t, "0123", chain("0"))
assert.Equal(t, "0123", pipe("0"))

// chain functions
chain2 := Pipe(
// pipe functions
pipe2 := Pipe(
func(foo *foo) *foo {
foo.Name = "bar"
return foo
Expand All @@ -153,7 +153,7 @@ func TestPipe(t *testing.T) {
assert.Equal(t, "foo", f.Name)
assert.Equal(t, 0, f.Age)

got := chain2(f)
got := pipe2(f)
assert.Equal(t, "bar", got.Name)
assert.Equal(t, 18, got.Age)
}
Expand Down Expand Up @@ -263,8 +263,8 @@ func TestScan_ComplexStruct(t *testing.T) {
}

func TestPipeWithErr(t *testing.T) {
// chain functions
chain := PipeWithErr(
// pipe functions
pipe := PipeWithErr(
func(s string) (string, error) {
return s + "1", nil
},
Expand All @@ -276,12 +276,12 @@ func TestPipeWithErr(t *testing.T) {
},
)

got, err := chain("0")
got, err := pipe("0")
assert.Nil(t, err)
assert.Equal(t, "0123", got)

// chain functions
chain2 := PipeWithErr(
// pipe functions
pipe2 := PipeWithErr(
func(foo *foo) (*foo, error) {
foo.Name = "bar"
return foo, nil
Expand All @@ -296,13 +296,13 @@ func TestPipeWithErr(t *testing.T) {
assert.Equal(t, "foo", f.Name)
assert.Equal(t, 0, f.Age)

got2, err := chain2(f)
got2, err := pipe2(f)
assert.Nil(t, err)
assert.Equal(t, "bar", got2.Name)
assert.Equal(t, 18, got2.Age)

// context
chain3 := PipeWithErr(
pipe3 := PipeWithErr(
func(ctx context.Context) (context.Context, error) {
return context.WithValue(ctx, "foo", "bar"), nil //nolint:revive,staticcheck
},
Expand All @@ -311,13 +311,13 @@ func TestPipeWithErr(t *testing.T) {
},
)

ctx, err := chain3(context.Background())
ctx, err := pipe3(context.Background())
assert.NoError(t, err)
assert.Equal(t, "bar", ctx.Value("foo"))
assert.Equal(t, "baz", ctx.Value("bar"))

// context with error
chain4 := PipeWithErr(
pipe4 := PipeWithErr(
func(ctx context.Context) (context.Context, error) {
return context.WithValue(ctx, "foo", "bar"), nil //nolint:revive,staticcheck
},
Expand All @@ -326,7 +326,7 @@ func TestPipeWithErr(t *testing.T) {
},
)

ctx, err = chain4(context.Background())
ctx, err = pipe4(context.Background())
assert.Error(t, err)
assert.Nil(t, ctx)
}
Expand Down
2 changes: 1 addition & 1 deletion helper/proxy.go → helpers/proxy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helper
package helpers

type Proxy[T any] struct {
target T
Expand Down
2 changes: 1 addition & 1 deletion helper/proxy_test.go → helpers/proxy_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helper
package helpers

import (
"testing"
Expand Down

0 comments on commit f07fd25

Please sign in to comment.