Skip to content

Commit

Permalink
use any replace interface{}
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed May 26, 2023
1 parent 420be00 commit b123642
Show file tree
Hide file tree
Showing 30 changed files with 253 additions and 252 deletions.
4 changes: 2 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

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

// NewAuth return auth obj
Expand Down
4 changes: 2 additions & 2 deletions auth/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewBasicAuth(username, password string) *BasicAuth {
}

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

// UnaryInterceptor define unary interceptor
func (b *BasicAuth) UnaryInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
func (b *BasicAuth) UnaryInterceptor(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
if err := b.doAuth(ctx); err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions client/interceptor/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

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

func (s *retryStream) SendMsg(m interface{}) error {
func (s *retryStream) SendMsg(m any) error {
s.mux.Lock()
s.sent = m
s.mux.Unlock()
return s.getStream().SendMsg(m)
}

func (s *retryStream) RecvMsg(m interface{}) (err error) {
func (s *retryStream) RecvMsg(m any) (err error) {
if err = s.ClientStream.RecvMsg(m); err == nil || errors.Is(err, context.Canceled) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion client/interceptor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type retryStream struct {
ctx context.Context
grpc.ClientStream
mux sync.RWMutex
sent interface{}
sent any
newStream func() (grpc.ClientStream, error)
retryOpts RetryOptions
}
Expand Down
32 changes: 16 additions & 16 deletions cluster/calcium/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func (h *CreateLambdaHandler) Typ() string {
}

// Check .
func (h *CreateLambdaHandler) Check(context.Context, interface{}) (bool, error) {
func (h *CreateLambdaHandler) Check(context.Context, any) (bool, error) {
return true, nil
}

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

// Decode .
func (h *CreateLambdaHandler) Decode(bs []byte) (interface{}, error) {
func (h *CreateLambdaHandler) Decode(bs []byte) (any, error) {
return string(bs), nil
}

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

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

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

// Decode .
func (h *CreateWorkloadHandler) Decode(bs []byte) (interface{}, error) {
func (h *CreateWorkloadHandler) Decode(bs []byte) (any, error) {
wrk := &types.Workload{}
err := json.Unmarshal(bs, wrk)
return wrk, err
}

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

Expand Down Expand Up @@ -210,15 +210,15 @@ func (h *WorkloadResourceAllocatedHandler) Typ() string {
}

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

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

// Decode .
func (h *WorkloadResourceAllocatedHandler) Decode(bytes []byte) (interface{}, error) {
func (h *WorkloadResourceAllocatedHandler) Decode(bytes []byte) (any, error) {
nodes := []*types.Node{}
return nodes, json.Unmarshal(bytes, &nodes)
}

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

Expand Down Expand Up @@ -281,15 +281,15 @@ func (h *ProcessingCreatedHandler) Typ() string {
}

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

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

// Decode .
func (h *ProcessingCreatedHandler) Decode(bs []byte) (interface{}, error) {
func (h *ProcessingCreatedHandler) Decode(bs []byte) (any, error) {
processing := &types.Processing{}
return processing, json.Unmarshal(bs, processing)
}

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

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b
github.com/panjf2000/ants/v2 v2.7.3
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/projecteru2/libyavirt v0.0.0-20230517062159-0c31f81550f3
github.com/projecteru2/libyavirt v0.0.0-20230524090109-0faf050e0f3b
github.com/prometheus/client_golang v1.15.0
github.com/rs/zerolog v1.29.1
github.com/sanity-io/litter v1.5.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/projecteru2/libyavirt v0.0.0-20230517062159-0c31f81550f3 h1:pjNFOoEalyROX9YfdxFXaNg4liZV/RASfhaVqJ4EnBQ=
github.com/projecteru2/libyavirt v0.0.0-20230517062159-0c31f81550f3/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw=
github.com/projecteru2/libyavirt v0.0.0-20230524090109-0faf050e0f3b h1:mXvbNYdr2uh2mhk5HdiBBSc9DhaR2RuulURaXhJaP2I=
github.com/projecteru2/libyavirt v0.0.0-20230524090109-0faf050e0f3b/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
Expand Down
26 changes: 13 additions & 13 deletions log/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// Fields is a wrapper for zerolog.Entry
// we need to insert some sentry captures here
type Fields struct {
kv *haxmap.Map[string, interface{}]
kv *haxmap.Map[string, any]
}

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

// WithField add kv into log entry
func WithField(key string, value interface{}) *Fields {
r := haxmap.New[string, interface{}]()
func WithField(key string, value any) *Fields {
r := haxmap.New[string, any]()
r.Set(key, value)
return &Fields{
kv: r,
}
}

// WithField .
func (f *Fields) WithField(key string, value interface{}) *Fields {
func (f *Fields) WithField(key string, value any) *Fields {
f.kv.Set(key, value)
return f
}

// Fatalf forwards to sentry
func (f Fields) Fatalf(ctx context.Context, err error, format string, args ...interface{}) {
func (f Fields) Fatalf(ctx context.Context, err error, format string, args ...any) {
fatalf(ctx, err, format, f.kv, args...)
}

// Warnf is Warnf
func (f Fields) Warnf(ctx context.Context, format string, args ...interface{}) {
func (f Fields) Warnf(ctx context.Context, format string, args ...any) {
warnf(ctx, format, f.kv, args...)
}

// Warn is Warn
func (f Fields) Warn(ctx context.Context, args ...interface{}) {
func (f Fields) Warn(ctx context.Context, args ...any) {
f.Warnf(ctx, "%+v", args...)
}

// Infof is Infof
func (f Fields) Infof(ctx context.Context, format string, args ...interface{}) {
func (f Fields) Infof(ctx context.Context, format string, args ...any) {
infof(ctx, format, f.kv, args...)
}

// Info is Info
func (f Fields) Info(ctx context.Context, args ...interface{}) {
func (f Fields) Info(ctx context.Context, args ...any) {
f.Infof(ctx, "%+v", args...)
}

// Debugf is Debugf
func (f Fields) Debugf(ctx context.Context, format string, args ...interface{}) {
func (f Fields) Debugf(ctx context.Context, format string, args ...any) {
debugf(ctx, format, f.kv, args...)
}

// Debug is Debug
func (f Fields) Debug(ctx context.Context, args ...interface{}) {
func (f Fields) Debug(ctx context.Context, args ...any) {
f.Debugf(ctx, "%+v", args...)
}

// Errorf forwards to sentry
func (f Fields) Errorf(ctx context.Context, err error, format string, args ...interface{}) {
func (f Fields) Errorf(ctx context.Context, err error, format string, args ...any) {
errorf(ctx, err, format, f.kv, args...)
}

// Error forwards to sentry
func (f Fields) Error(ctx context.Context, err error, args ...interface{}) {
func (f Fields) Error(ctx context.Context, err error, args ...any) {
f.Errorf(ctx, err, "%+v", args...)
}
18 changes: 9 additions & 9 deletions log/inner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ import (
"github.com/rs/zerolog"
)

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

func warnf(_ context.Context, format string, fields *haxmap.Map[string, interface{}], args ...interface{}) {
func warnf(_ context.Context, format string, fields *haxmap.Map[string, any], args ...any) {
args = argsValidate(args)
f := globalLogger.Warn()
wrap(f, fields).Msgf(format, args...)
}

func infof(_ context.Context, format string, fields *haxmap.Map[string, interface{}], args ...interface{}) {
func infof(_ context.Context, format string, fields *haxmap.Map[string, any], args ...any) {
args = argsValidate(args)
f := globalLogger.Info()
wrap(f, fields).Msgf(format, args...)
}

func debugf(_ context.Context, format string, fields *haxmap.Map[string, interface{}], args ...interface{}) {
func debugf(_ context.Context, format string, fields *haxmap.Map[string, any], args ...any) {
args = argsValidate(args)
f := globalLogger.Debug()
wrap(f, fields).Msgf(format, args...)
}

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

func argsValidate(args []interface{}) []interface{} {
func argsValidate(args []any) []any {
if len(args) > 0 {
return args
}
return []interface{}{""}
return []any{""}
}

func wrap(f *zerolog.Event, kv *haxmap.Map[string, interface{}]) *zerolog.Event {
func wrap(f *zerolog.Event, kv *haxmap.Map[string, any]) *zerolog.Event {
if kv == nil {
return f
}
kv.ForEach(func(k string, v interface{}) bool {
kv.ForEach(func(k string, v any) bool {
f = f.Interface(k, v)
return true
})
Expand Down
Loading

0 comments on commit b123642

Please sign in to comment.