Skip to content

Commit b123642

Browse files
committed
use any replace interface{}
1 parent 420be00 commit b123642

30 files changed

+253
-252
lines changed

auth/auth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
// Auth define auth obj
1313
type Auth interface {
14-
StreamInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
15-
UnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
14+
StreamInterceptor(srv any, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
15+
UnaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)
1616
}
1717

1818
// NewAuth return auth obj

auth/simple/simple.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewBasicAuth(username, password string) *BasicAuth {
2121
}
2222

2323
// StreamInterceptor define stream interceptor
24-
func (b *BasicAuth) StreamInterceptor(srv interface{}, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
24+
func (b *BasicAuth) StreamInterceptor(srv any, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
2525
ctx := stream.Context()
2626
if err := b.doAuth(ctx); err != nil {
2727
return err
@@ -30,7 +30,7 @@ func (b *BasicAuth) StreamInterceptor(srv interface{}, stream grpc.ServerStream,
3030
}
3131

3232
// UnaryInterceptor define unary interceptor
33-
func (b *BasicAuth) UnaryInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
33+
func (b *BasicAuth) UnaryInterceptor(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
3434
if err := b.doAuth(ctx); err != nil {
3535
return nil, err
3636
}

client/interceptor/retry.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// NewUnaryRetry makes unary RPC retry on error
1414
func NewUnaryRetry(retryOpts RetryOptions) grpc.UnaryClientInterceptor {
15-
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
15+
return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
1616
return backoff.Retry(func() error {
1717
return invoker(ctx, method, req, reply, cc, opts...)
1818
}, backoff.WithMaxRetries(backoff.WithContext(backoff.NewExponentialBackOff(), ctx), uint64(retryOpts.Max)))
@@ -45,14 +45,14 @@ func NewStreamRetry(retryOpts RetryOptions) grpc.StreamClientInterceptor {
4545
}
4646
}
4747

48-
func (s *retryStream) SendMsg(m interface{}) error {
48+
func (s *retryStream) SendMsg(m any) error {
4949
s.mux.Lock()
5050
s.sent = m
5151
s.mux.Unlock()
5252
return s.getStream().SendMsg(m)
5353
}
5454

55-
func (s *retryStream) RecvMsg(m interface{}) (err error) {
55+
func (s *retryStream) RecvMsg(m any) (err error) {
5656
if err = s.ClientStream.RecvMsg(m); err == nil || errors.Is(err, context.Canceled) {
5757
return
5858
}

client/interceptor/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type retryStream struct {
1616
ctx context.Context
1717
grpc.ClientStream
1818
mux sync.RWMutex
19-
sent interface{}
19+
sent any
2020
newStream func() (grpc.ClientStream, error)
2121
retryOpts RetryOptions
2222
}

cluster/calcium/wal.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ func (h *CreateLambdaHandler) Typ() string {
5959
}
6060

6161
// Check .
62-
func (h *CreateLambdaHandler) Check(context.Context, interface{}) (bool, error) {
62+
func (h *CreateLambdaHandler) Check(context.Context, any) (bool, error) {
6363
return true, nil
6464
}
6565

6666
// Encode .
67-
func (h *CreateLambdaHandler) Encode(raw interface{}) ([]byte, error) {
67+
func (h *CreateLambdaHandler) Encode(raw any) ([]byte, error) {
6868
workloadID, ok := raw.(string)
6969
if !ok {
7070
return nil, errors.Wrapf(types.ErrInvalidWALDataType, "%+v", raw)
@@ -73,12 +73,12 @@ func (h *CreateLambdaHandler) Encode(raw interface{}) ([]byte, error) {
7373
}
7474

7575
// Decode .
76-
func (h *CreateLambdaHandler) Decode(bs []byte) (interface{}, error) {
76+
func (h *CreateLambdaHandler) Decode(bs []byte) (any, error) {
7777
return string(bs), nil
7878
}
7979

8080
// Handle .
81-
func (h *CreateLambdaHandler) Handle(ctx context.Context, raw interface{}) error {
81+
func (h *CreateLambdaHandler) Handle(ctx context.Context, raw any) error {
8282
workloadID, ok := raw.(string)
8383
if !ok {
8484
return errors.Wrapf(types.ErrInvalidWALDataType, "%+v", raw)
@@ -133,7 +133,7 @@ func (h *CreateWorkloadHandler) Typ() string {
133133
}
134134

135135
// Check .
136-
func (h *CreateWorkloadHandler) Check(_ context.Context, raw interface{}) (handle bool, err error) {
136+
func (h *CreateWorkloadHandler) Check(_ context.Context, raw any) (handle bool, err error) {
137137
_, ok := raw.(*types.Workload)
138138
if !ok {
139139
return false, errors.Wrapf(types.ErrInvalidWALDataType, "%+v", raw)
@@ -142,7 +142,7 @@ func (h *CreateWorkloadHandler) Check(_ context.Context, raw interface{}) (handl
142142
}
143143

144144
// Encode .
145-
func (h *CreateWorkloadHandler) Encode(raw interface{}) ([]byte, error) {
145+
func (h *CreateWorkloadHandler) Encode(raw any) ([]byte, error) {
146146
wrk, ok := raw.(*types.Workload)
147147
if !ok {
148148
return nil, errors.Wrapf(types.ErrInvalidWALDataType, "%+v", raw)
@@ -151,14 +151,14 @@ func (h *CreateWorkloadHandler) Encode(raw interface{}) ([]byte, error) {
151151
}
152152

153153
// Decode .
154-
func (h *CreateWorkloadHandler) Decode(bs []byte) (interface{}, error) {
154+
func (h *CreateWorkloadHandler) Decode(bs []byte) (any, error) {
155155
wrk := &types.Workload{}
156156
err := json.Unmarshal(bs, wrk)
157157
return wrk, err
158158
}
159159

160160
// Handle will remove instance, remove meta, restore resource
161-
func (h *CreateWorkloadHandler) Handle(ctx context.Context, raw interface{}) (err error) {
161+
func (h *CreateWorkloadHandler) Handle(ctx context.Context, raw any) (err error) {
162162
wrk, _ := raw.(*types.Workload)
163163
logger := log.WithFunc("wal.CreateWorkloadHandler.Handle").WithField("ID", wrk.ID).WithField("node", wrk.Nodename)
164164

@@ -210,15 +210,15 @@ func (h *WorkloadResourceAllocatedHandler) Typ() string {
210210
}
211211

212212
// Check .
213-
func (h *WorkloadResourceAllocatedHandler) Check(_ context.Context, raw interface{}) (bool, error) {
213+
func (h *WorkloadResourceAllocatedHandler) Check(_ context.Context, raw any) (bool, error) {
214214
if _, ok := raw.([]*types.Node); !ok {
215215
return false, errors.Wrapf(types.ErrInvalidWALDataType, "%+v", raw)
216216
}
217217
return true, nil
218218
}
219219

220220
// Encode .
221-
func (h *WorkloadResourceAllocatedHandler) Encode(raw interface{}) ([]byte, error) {
221+
func (h *WorkloadResourceAllocatedHandler) Encode(raw any) ([]byte, error) {
222222
nodes, ok := raw.([]*types.Node)
223223
if !ok {
224224
return nil, errors.Wrapf(types.ErrInvalidWALDataType, "%+v", raw)
@@ -227,13 +227,13 @@ func (h *WorkloadResourceAllocatedHandler) Encode(raw interface{}) ([]byte, erro
227227
}
228228

229229
// Decode .
230-
func (h *WorkloadResourceAllocatedHandler) Decode(bytes []byte) (interface{}, error) {
230+
func (h *WorkloadResourceAllocatedHandler) Decode(bytes []byte) (any, error) {
231231
nodes := []*types.Node{}
232232
return nodes, json.Unmarshal(bytes, &nodes)
233233
}
234234

235235
// Handle .
236-
func (h *WorkloadResourceAllocatedHandler) Handle(ctx context.Context, raw interface{}) (err error) {
236+
func (h *WorkloadResourceAllocatedHandler) Handle(ctx context.Context, raw any) (err error) {
237237
nodes, _ := raw.([]*types.Node)
238238
logger := log.WithFunc("wal.WorkloadResourceAllocatedHandler.Handle").WithField("event", eventWorkloadResourceAllocated)
239239

@@ -281,15 +281,15 @@ func (h *ProcessingCreatedHandler) Typ() string {
281281
}
282282

283283
// Check .
284-
func (h ProcessingCreatedHandler) Check(_ context.Context, raw interface{}) (bool, error) {
284+
func (h ProcessingCreatedHandler) Check(_ context.Context, raw any) (bool, error) {
285285
if _, ok := raw.(*types.Processing); !ok {
286286
return false, errors.Wrapf(types.ErrInvalidWALDataType, "%+v", raw)
287287
}
288288
return true, nil
289289
}
290290

291291
// Encode .
292-
func (h *ProcessingCreatedHandler) Encode(raw interface{}) ([]byte, error) {
292+
func (h *ProcessingCreatedHandler) Encode(raw any) ([]byte, error) {
293293
processing, ok := raw.(*types.Processing)
294294
if !ok {
295295
return nil, errors.Wrapf(types.ErrInvalidWALDataType, "%+v", raw)
@@ -298,13 +298,13 @@ func (h *ProcessingCreatedHandler) Encode(raw interface{}) ([]byte, error) {
298298
}
299299

300300
// Decode .
301-
func (h *ProcessingCreatedHandler) Decode(bs []byte) (interface{}, error) {
301+
func (h *ProcessingCreatedHandler) Decode(bs []byte) (any, error) {
302302
processing := &types.Processing{}
303303
return processing, json.Unmarshal(bs, processing)
304304
}
305305

306306
// Handle .
307-
func (h *ProcessingCreatedHandler) Handle(ctx context.Context, raw interface{}) (err error) {
307+
func (h *ProcessingCreatedHandler) Handle(ctx context.Context, raw any) (err error) {
308308
processing, _ := raw.(*types.Processing)
309309
logger := log.WithFunc("wal.ProcessingCreatedHandler.Handle").WithField("event", eventProcessingCreated).WithField("ident", processing.Ident)
310310

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
2424
github.com/panjf2000/ants/v2 v2.7.3
2525
github.com/patrickmn/go-cache v2.1.0+incompatible
26-
github.com/projecteru2/libyavirt v0.0.0-20230517062159-0c31f81550f3
26+
github.com/projecteru2/libyavirt v0.0.0-20230524090109-0faf050e0f3b
2727
github.com/prometheus/client_golang v1.15.0
2828
github.com/rs/zerolog v1.29.1
2929
github.com/sanity-io/litter v1.5.5

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
459459
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
460460
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
461461
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
462-
github.com/projecteru2/libyavirt v0.0.0-20230517062159-0c31f81550f3 h1:pjNFOoEalyROX9YfdxFXaNg4liZV/RASfhaVqJ4EnBQ=
463-
github.com/projecteru2/libyavirt v0.0.0-20230517062159-0c31f81550f3/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw=
462+
github.com/projecteru2/libyavirt v0.0.0-20230524090109-0faf050e0f3b h1:mXvbNYdr2uh2mhk5HdiBBSc9DhaR2RuulURaXhJaP2I=
463+
github.com/projecteru2/libyavirt v0.0.0-20230524090109-0faf050e0f3b/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw=
464464
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
465465
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
466466
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=

log/field.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
// Fields is a wrapper for zerolog.Entry
1010
// we need to insert some sentry captures here
1111
type Fields struct {
12-
kv *haxmap.Map[string, interface{}]
12+
kv *haxmap.Map[string, any]
1313
}
1414

1515
// WithFunc is short for WithField
@@ -18,61 +18,61 @@ func WithFunc(fname string) *Fields {
1818
}
1919

2020
// WithField add kv into log entry
21-
func WithField(key string, value interface{}) *Fields {
22-
r := haxmap.New[string, interface{}]()
21+
func WithField(key string, value any) *Fields {
22+
r := haxmap.New[string, any]()
2323
r.Set(key, value)
2424
return &Fields{
2525
kv: r,
2626
}
2727
}
2828

2929
// WithField .
30-
func (f *Fields) WithField(key string, value interface{}) *Fields {
30+
func (f *Fields) WithField(key string, value any) *Fields {
3131
f.kv.Set(key, value)
3232
return f
3333
}
3434

3535
// Fatalf forwards to sentry
36-
func (f Fields) Fatalf(ctx context.Context, err error, format string, args ...interface{}) {
36+
func (f Fields) Fatalf(ctx context.Context, err error, format string, args ...any) {
3737
fatalf(ctx, err, format, f.kv, args...)
3838
}
3939

4040
// Warnf is Warnf
41-
func (f Fields) Warnf(ctx context.Context, format string, args ...interface{}) {
41+
func (f Fields) Warnf(ctx context.Context, format string, args ...any) {
4242
warnf(ctx, format, f.kv, args...)
4343
}
4444

4545
// Warn is Warn
46-
func (f Fields) Warn(ctx context.Context, args ...interface{}) {
46+
func (f Fields) Warn(ctx context.Context, args ...any) {
4747
f.Warnf(ctx, "%+v", args...)
4848
}
4949

5050
// Infof is Infof
51-
func (f Fields) Infof(ctx context.Context, format string, args ...interface{}) {
51+
func (f Fields) Infof(ctx context.Context, format string, args ...any) {
5252
infof(ctx, format, f.kv, args...)
5353
}
5454

5555
// Info is Info
56-
func (f Fields) Info(ctx context.Context, args ...interface{}) {
56+
func (f Fields) Info(ctx context.Context, args ...any) {
5757
f.Infof(ctx, "%+v", args...)
5858
}
5959

6060
// Debugf is Debugf
61-
func (f Fields) Debugf(ctx context.Context, format string, args ...interface{}) {
61+
func (f Fields) Debugf(ctx context.Context, format string, args ...any) {
6262
debugf(ctx, format, f.kv, args...)
6363
}
6464

6565
// Debug is Debug
66-
func (f Fields) Debug(ctx context.Context, args ...interface{}) {
66+
func (f Fields) Debug(ctx context.Context, args ...any) {
6767
f.Debugf(ctx, "%+v", args...)
6868
}
6969

7070
// Errorf forwards to sentry
71-
func (f Fields) Errorf(ctx context.Context, err error, format string, args ...interface{}) {
71+
func (f Fields) Errorf(ctx context.Context, err error, format string, args ...any) {
7272
errorf(ctx, err, format, f.kv, args...)
7373
}
7474

7575
// Error forwards to sentry
76-
func (f Fields) Error(ctx context.Context, err error, args ...interface{}) {
76+
func (f Fields) Error(ctx context.Context, err error, args ...any) {
7777
f.Errorf(ctx, err, "%+v", args...)
7878
}

log/inner.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@ import (
88
"github.com/rs/zerolog"
99
)
1010

11-
func fatalf(ctx context.Context, err error, format string, fields *haxmap.Map[string, interface{}], args ...interface{}) {
11+
func fatalf(ctx context.Context, err error, format string, fields *haxmap.Map[string, any], args ...any) {
1212
args = argsValidate(args)
1313
reportToSentry(ctx, sentry.LevelFatal, err, format, args...)
1414
f := globalLogger.Fatal()
1515
wrap(f, fields).Err(err).Msgf(format, args...)
1616
}
1717

18-
func warnf(_ context.Context, format string, fields *haxmap.Map[string, interface{}], args ...interface{}) {
18+
func warnf(_ context.Context, format string, fields *haxmap.Map[string, any], args ...any) {
1919
args = argsValidate(args)
2020
f := globalLogger.Warn()
2121
wrap(f, fields).Msgf(format, args...)
2222
}
2323

24-
func infof(_ context.Context, format string, fields *haxmap.Map[string, interface{}], args ...interface{}) {
24+
func infof(_ context.Context, format string, fields *haxmap.Map[string, any], args ...any) {
2525
args = argsValidate(args)
2626
f := globalLogger.Info()
2727
wrap(f, fields).Msgf(format, args...)
2828
}
2929

30-
func debugf(_ context.Context, format string, fields *haxmap.Map[string, interface{}], args ...interface{}) {
30+
func debugf(_ context.Context, format string, fields *haxmap.Map[string, any], args ...any) {
3131
args = argsValidate(args)
3232
f := globalLogger.Debug()
3333
wrap(f, fields).Msgf(format, args...)
3434
}
3535

36-
func errorf(ctx context.Context, err error, format string, fields *haxmap.Map[string, interface{}], args ...interface{}) {
36+
func errorf(ctx context.Context, err error, format string, fields *haxmap.Map[string, any], args ...any) {
3737
if err == nil {
3838
return
3939
}
@@ -43,18 +43,18 @@ func errorf(ctx context.Context, err error, format string, fields *haxmap.Map[st
4343
wrap(f, fields).Stack().Err(err).Msgf(format, args...)
4444
}
4545

46-
func argsValidate(args []interface{}) []interface{} {
46+
func argsValidate(args []any) []any {
4747
if len(args) > 0 {
4848
return args
4949
}
50-
return []interface{}{""}
50+
return []any{""}
5151
}
5252

53-
func wrap(f *zerolog.Event, kv *haxmap.Map[string, interface{}]) *zerolog.Event {
53+
func wrap(f *zerolog.Event, kv *haxmap.Map[string, any]) *zerolog.Event {
5454
if kv == nil {
5555
return f
5656
}
57-
kv.ForEach(func(k string, v interface{}) bool {
57+
kv.ForEach(func(k string, v any) bool {
5858
f = f.Interface(k, v)
5959
return true
6060
})

0 commit comments

Comments
 (0)