Skip to content

Commit 69bf920

Browse files
authored
fix: upgrade dix, funk (#62)
1 parent b4fb51e commit 69bf920

File tree

25 files changed

+216
-427
lines changed

25 files changed

+216
-427
lines changed

.github/workflows/lint-test.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
16-
15+
- uses: "actions/checkout@v4"
1716
- name: Set up Go
18-
uses: actions/setup-go@v2
17+
uses: actions/setup-go@v5
1918
with:
20-
go-version: 1.22
19+
go-version-file: 'go.mod'
2120

2221
- name: golangci-lint
23-
uses: golangci/golangci-lint-action@v2
22+
uses: golangci/golangci-lint-action@v8
2423
with:
2524
skip-go-installation: true
2625
args: --timeout 3m --verbose
@@ -30,12 +29,10 @@ jobs:
3029

3130
steps:
3231
- name: Checkout
33-
uses: actions/checkout@v2
34-
35-
- name: Set up Go
36-
uses: actions/setup-go@v2
32+
uses: actions/checkout@v4
33+
- uses: actions/setup-go@v5
3734
with:
38-
go-version: 1.22
35+
go-version-file: 'go.mod'
3936

4037
- name: Collect dependencies
4138
run: |
@@ -46,7 +43,7 @@ jobs:
4643
run: gotestsum --junitfile unit-tests.xml -- -gcflags=-l ./...
4744

4845
- name: Test report
49-
uses: dorny/test-reporter@v1
46+
uses: dorny/test-reporter@v2
5047
if: success() || failure()
5148
with:
5249
name: Test report

.github/workflows/release.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.golangci.yaml

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1+
version: "2"
12
linters:
2-
fast: true
3-
disable-all: true
3+
default: none
44
enable:
5-
# - bodyclose # checks whether HTTP response body is closed successfully
6-
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
7-
- gosimple # Linter for Go source code that specializes in simplifying a code
8-
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
9-
# - ineffassign # Detects when assignments to existing variables are not used
10-
# - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
11-
# - goconst # Finds repeated strings that could be replaced by a constant
12-
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
13-
# - goprintffuncname # Checks that printf-like functions are named with f at the end
14-
# - nolintlint # Reports ill-formed or insufficient nolint directives
15-
# - rowserrcheck # checks whether Err of rows is checked successfully
16-
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
17-
# - unconvert # Remove unnecessary type conversions
18-
# - unparam # Reports unused function parameters
19-
# - unused # Checks Go code for unused constants, variables, functions and types
20-
21-
issues:
22-
exclude-dirs:
23-
- internal/example
24-
- cmds
25-
- vendor
26-
- pkg/proto
27-
exclude-generated: strict
28-
exclude-dirs-use-default: true
29-
exclude-case-sensitive: false
30-
exclude-use-default: true
5+
- govet
6+
exclusions:
7+
presets:
8+
- comments
9+
- common-false-positives
10+
- legacy
11+
- std-error-handling
12+
paths:
13+
- internal/example
14+
- cmds
15+
- vendor
16+
- pkg/proto
17+
- third_party$
18+
- builtin$
19+
- examples$
20+
formatters:
21+
enable:
22+
- goimports
23+
- gofmt
24+
exclusions:
25+
paths:
26+
- internal/example
27+
- cmds
28+
- vendor
29+
- pkg/proto
30+
- third_party$
31+
- builtin$
32+
- examples$

.goreleaser.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protobuf:
4444
.PHONY: lint
4545
lint:
4646
golangci-lint --version
47-
golangci-lint run --timeout 3m --verbose ./...
47+
golangci-lint run --timeout=10m --verbose
4848

4949
install-protoc:
5050
go install -v ./cmds/protoc-gen-lava

clients/grpcc/client.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/pubgo/funk/errors"
1010
"github.com/pubgo/funk/log"
1111
"github.com/pubgo/funk/recovery"
12-
"github.com/pubgo/funk/result"
12+
"github.com/pubgo/funk/v2/result"
1313
"github.com/pubgo/funk/vars"
1414
"github.com/pubgo/lava/clients/grpcc/grpcc_config"
1515
"github.com/pubgo/lava/core/metrics"
@@ -47,53 +47,53 @@ type clientImpl struct {
4747
middlewares []lava.Middleware
4848
}
4949

50-
func (t *clientImpl) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...grpc.CallOption) (err error) {
50+
func (t *clientImpl) Invoke(ctx context.Context, method string, args, reply any, opts ...grpc.CallOption) (err error) {
5151
defer recovery.Err(&err, func(err error) error {
5252
return errors.WrapTag(err, errors.T("method", method), errors.T("args", args))
5353
})
5454

5555
conn := t.Get()
5656
if conn.IsErr() {
57-
return errors.Wrapf(conn.Err(), "failed to get grpc client, service=%s, method=%s", t.cfg.Service, method)
57+
return errors.Wrapf(conn.GetErr(), "failed to get grpc client, service=%s, method=%s", t.cfg.Service, method)
5858
}
5959

60-
return conn.Unwrap().Invoke(ctx, method, args, reply, opts...)
60+
return conn.Must().Invoke(ctx, method, args, reply, opts...)
6161
}
6262

6363
func (t *clientImpl) Healthy(ctx context.Context) error {
6464
conn := t.Get()
6565
if conn.IsErr() {
66-
return errors.Wrapf(conn.Err(), "failed to get grpc client, service=%s, method=healthy", t.cfg.Service)
66+
return errors.Wrapf(conn.GetErr(), "failed to get grpc client, service=%s, method=healthy", t.cfg.Service)
6767
}
6868

69-
_, err := grpc_health_v1.NewHealthClient(conn.Unwrap()).Check(ctx, &grpc_health_v1.HealthCheckRequest{})
69+
_, err := grpc_health_v1.NewHealthClient(conn.Must()).Check(ctx, &grpc_health_v1.HealthCheckRequest{})
7070
return errors.Wrapf(err, "service %s heath check failed", t.cfg.Service)
7171
}
7272

7373
func (t *clientImpl) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) {
7474
conn := t.Get()
7575
if conn.IsErr() {
76-
return nil, errors.Wrapf(conn.Err(), "failed to get grpc client, service=%s, method=%s", t.cfg.Service, method)
76+
return nil, errors.Wrapf(conn.GetErr(), "failed to get grpc client, service=%s, method=%s", t.cfg.Service, method)
7777
}
7878

79-
c, err1 := conn.Unwrap().NewStream(ctx, desc, method, opts...)
79+
c, err1 := conn.Must().NewStream(ctx, desc, method, opts...)
8080
return c, errors.Wrap(err1, method)
8181
}
8282

8383
// Get new grpc client
8484
func (t *clientImpl) Get() (r result.Result[grpc.ClientConnInterface]) {
85-
defer recovery.Result(&r)
85+
defer result.RecoveryErr(&r)
8686

8787
if t.conn != nil {
88-
return r.WithVal(t.conn)
88+
return r.WithValue(t.conn)
8989
}
9090

9191
t.mu.Lock()
9292
defer t.mu.Unlock()
9393

9494
// 双检, 避免多次创建
9595
if t.conn != nil {
96-
return r.WithVal(t.conn)
96+
return r.WithValue(t.conn)
9797
}
9898

9999
conn, err := createConn(t.cfg, t.log, t.middlewares)
@@ -102,5 +102,5 @@ func (t *clientImpl) Get() (r result.Result[grpc.ClientConnInterface]) {
102102
}
103103

104104
t.conn = conn
105-
return r.WithVal(t.conn)
105+
return r.WithValue(t.conn)
106106
}

clients/grpcc/grpcc_resolver/discoverybuilder.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ func (d *discoveryBuilder) Build(target resolver.Target, cc resolver.ClientConn,
9696

9797
// target.Endpoint是服务的名字, 是项目启动的时候注册中心中注册的项目名字
9898
// GetService根据服务名字获取注册中心该项目所有服务
99-
services := d.disco.GetService(context.Background(), srv).Unwrap(func(err error) error {
100-
return errors.Wrapf(err, "failed to GetService, srv=%s", srv)
101-
})
99+
services := d.disco.GetService(context.Background(), srv).
100+
MapErr(func(err error) error {
101+
return errors.Wrapf(err, "failed to GetService, srv=%s", srv)
102+
}).Unwrap(&gErr)
102103

103104
// 启动后,更新服务地址
104105
d.updateService(services...)
@@ -109,9 +110,10 @@ func (d *discoveryBuilder) Build(target resolver.Target, cc resolver.ClientConn,
109110
logs.Info().Msgf("discovery builder UpdateState, address=%v", address)
110111
assert.MustF(cc.UpdateState(newState(address)), "update resolver address: %v", address)
111112

112-
w := d.disco.Watch(context.Background(), srv).Unwrap(func(err error) error {
113-
return errors.Wrapf(err, "target.Endpoint: %s", srv)
114-
})
113+
w := d.disco.Watch(context.Background(), srv).
114+
MapErr(func(err error) error {
115+
return errors.Wrapf(err, "target.Endpoint: %s", srv)
116+
}).Unwrap(&gErr)
115117

116118
return &baseResolver{
117119
serviceName: srv,
@@ -126,24 +128,24 @@ func (d *discoveryBuilder) Build(target resolver.Target, cc resolver.ClientConn,
126128
default:
127129
res := w.Next()
128130
if res.IsErr() {
129-
if errors.Is(res.Err(), discovery.ErrWatcherStopped) {
131+
if errors.Is(res.GetErr(), discovery.ErrWatcherStopped) {
130132
return
131133
}
132134

133-
d.log.Err(res.Err(), ctx).Msg("failed to get service watcher event")
135+
d.log.Err(res.GetErr(), ctx).Msg("failed to get service watcher event")
134136

135-
if errors.Is(res.Err(), discovery.ErrTimeout) {
137+
if errors.Is(res.GetErr(), discovery.ErrTimeout) {
136138
continue
137139
}
138140

139141
continue
140142
}
141143

142144
// 注册中心删除服务
143-
if res.Unwrap().Action == lavapbv1.EventType_DELETE {
144-
d.delService(res.Unwrap().Service)
145+
if res.Must().Action == lavapbv1.EventType_DELETE {
146+
d.delService(res.Must().Service)
145147
} else {
146-
d.updateService(res.Unwrap().Service)
148+
d.updateService(res.Must().Service)
147149
}
148150

149151
logutil.ErrRecord(logs, try.Try(func() error {

clients/resty/aaa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"time"
66

7-
"github.com/pubgo/funk/result"
7+
"github.com/pubgo/funk/v2/result"
88
"github.com/valyala/fasthttp"
99
)
1010

clients/resty/client.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
"github.com/pubgo/funk/assert"
99
"github.com/pubgo/funk/config"
1010
"github.com/pubgo/funk/log"
11-
"github.com/pubgo/funk/recovery"
12-
"github.com/pubgo/funk/result"
1311
"github.com/pubgo/funk/retry"
12+
"github.com/pubgo/funk/v2/result"
1413
"github.com/valyala/fasthttp"
1514

1615
"github.com/pubgo/lava/core/metrics"
@@ -67,7 +66,7 @@ type Client struct {
6766
}
6867

6968
func (c *Client) Do(ctx context.Context, req *Request) (r result.Result[*fasthttp.Response]) {
70-
defer recovery.Result(&r)
69+
defer result.RecoveryErr(&r)
7170

7271
reqErr := doRequest(c, req)
7372
if reqErr.IsErr() {
@@ -82,5 +81,5 @@ func (c *Client) Do(ctx context.Context, req *Request) (r result.Result[*fasthtt
8281
return r.WithErr(err)
8382
}
8483

85-
return r.WithVal(resp.(*responseImpl).resp)
84+
return r.WithValue(resp.(*responseImpl).resp)
8685
}

cmds/grpcservercmd/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package grpcservercmd
22

33
import (
44
"context"
5+
56
"github.com/pubgo/dix"
67
"github.com/pubgo/funk/recovery"
78
"github.com/pubgo/funk/version"

0 commit comments

Comments
 (0)