Skip to content

Commit

Permalink
style: format code with Gofumpt and Prettier
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in 50cfcd3 according to the output
from Gofumpt and Prettier.

Details: #2733
Signed-off-by: kpango <[email protected]>
  • Loading branch information
deepsource-autofix[bot] authored and kpango committed Nov 6, 2024
1 parent 50cfcd3 commit 275597c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type cache[V any] struct {
cacher cacher.Type
expireDur time.Duration
expireCheckDur time.Duration
expiredHook func(context.Context, string)
expiredHook func(context.Context, string, V)
}

// New returns the Cache instance or error.
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/gache/gache.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type cache[V any] struct {
gache gache.Gache[V]
expireDur time.Duration
expireCheckDur time.Duration
expiredHook func(context.Context, string)
expiredHook func(context.Context, string, V)
}

// New loads a cache model and returns a new cache struct.
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/gache/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func WithGache[V any](g gache.Gache[V]) Option[V] {
}

// WithExpiredHook returns Option after set expiredHook when f is not nil.
func WithExpiredHook[V any](f func(context.Context, string)) Option[V] {
func WithExpiredHook[V any](f func(context.Context, string, V)) Option[V] {
return func(c *cache[V]) {
if f != nil {
c.expiredHook = f
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func defaultOptions[V any]() []Option[V] {
}

// WithExpiredHook returns Option after set expiredHook when f is not nil.
func WithExpiredHook[V any](f func(context.Context, string)) Option[V] {
func WithExpiredHook[V any](f func(context.Context, string, V)) Option[V] {
return func(c *cache[V]) {
if f != nil {
c.expiredHook = f
Expand Down
2 changes: 1 addition & 1 deletion internal/core/algorithm/ngt/ngt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func Test_gen(t *testing.T) {
objectType: Uint8,
mu: &sync.RWMutex{},
cmu: &sync.RWMutex{},
smu: &sync.Mutex{},
smu: &sync.Mutex{},
epl: DefaultErrorBufferLimit,
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/net/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func (d *dialer) tlsHandshake(
return tconn, nil
}

func (d *dialer) cacheExpireHook(ctx context.Context, addr string) {
func (d *dialer) cacheExpireHook(ctx context.Context, addr string, _ *dialerCache) {
if err := safety.RecoverFunc(func() (err error) {
_, err = d.lookup(ctx, addr)
return
Expand Down
5 changes: 3 additions & 2 deletions internal/net/dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,8 @@ func Test_dialer_dial(t *testing.T) {
func Test_dialer_cacheExpireHook(t *testing.T) {
t.Parallel()
type args struct {
addr string
addr string
cache *dialerCache
}
type want struct{}
type test struct {
Expand Down Expand Up @@ -1585,7 +1586,7 @@ func Test_dialer_cacheExpireHook(t *testing.T) {
test.beforeFunc(d)
}

d.cacheExpireHook(ctx, test.args.addr)
d.cacheExpireHook(ctx, test.args.addr, test.args.cache)
if err := checkFunc(d); err != nil {
tt.Errorf("error = %v", err)
}
Expand Down
9 changes: 7 additions & 2 deletions internal/safety/safety.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package safety

import (
"runtime"
"runtime/debug"

"github.com/vdaas/vald/internal/conv"
"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/info"
"github.com/vdaas/vald/internal/log"
Expand All @@ -35,16 +37,19 @@ func RecoverWithoutPanicFunc(fn func() error) func() error {

func recoverFn(fn func() error, withPanic bool) func() error {
return func() (err error) {
if fn == nil {
return nil
}
defer func() {
if r := recover(); r != nil {
infoStr := info.Get().String()
ds := debug.Stack()
infoStr := info.Get().String() + "\r\n" + conv.Btoa(ds)
log.Warnf("function %#v panic recovered: %#v\ninfo:\n%s", fn, r, infoStr)
switch x := r.(type) {
case runtime.Error:
err = errors.ErrRuntimeError(err, x)
if withPanic {
log.Errorf("recovered but this thread is going to panic: the reason is runtimer.Error\nerror:\t%v\ninfo:\n%s\nrecovered:\t%#v", err, infoStr, r)

panic(err)
}
case *string:
Expand Down

0 comments on commit 275597c

Please sign in to comment.