Skip to content

Commit

Permalink
Merge pull request #16604 from chenyahui/interface_to_any
Browse files Browse the repository at this point in the history
Use any instead of interface{}
  • Loading branch information
serathius authored Sep 18, 2023
2 parents fb8a315 + c0aa3b6 commit 0917288
Show file tree
Hide file tree
Showing 61 changed files with 227 additions and 227 deletions.
2 changes: 1 addition & 1 deletion client/internal/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (

// oneShotCtxValue is set on a context using WithValue(&oneShotValue) so
// that Do() will not retry a request
oneShotCtxValue interface{}
oneShotCtxValue any
)

var DefaultRequestTimeout = 5 * time.Second
Expand Down
4 changes: 2 additions & 2 deletions client/internal/v2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ func (f fakeCancelContext) Done() <-chan struct{} {
d <- struct{}{}
return d
}
func (f fakeCancelContext) Err() error { return errFakeCancelContext }
func (f fakeCancelContext) Value(key interface{}) interface{} { return 1 }
func (f fakeCancelContext) Err() error { return errFakeCancelContext }
func (f fakeCancelContext) Value(key any) any { return 1 }

func withTimeout(parent context.Context, timeout time.Duration) (
ctx context.Context,
Expand Down
10 changes: 5 additions & 5 deletions client/pkg/testutil/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ import (
"github.com/stretchr/testify/assert"
)

func copyToInterface(msg ...string) []interface{} {
newMsg := make([]interface{}, len(msg))
func copyToInterface(msg ...string) []any {
newMsg := make([]any, len(msg))
for i, v := range msg {
newMsg[i] = v
}
return newMsg
}

func AssertNil(t *testing.T, v interface{}) {
func AssertNil(t *testing.T, v any) {
t.Helper()
assert.Nil(t, v)
}

func AssertNotNil(t *testing.T, v interface{}) {
func AssertNotNil(t *testing.T, v any) {
t.Helper()
if v == nil {
t.Fatalf("expected non-nil, got %+v", v)
Expand All @@ -53,7 +53,7 @@ func AssertFalse(t *testing.T, v bool, msg ...string) {
assert.Equal(t, false, v, newMsg)
}

func isNil(v interface{}) bool {
func isNil(v any) bool {
if v == nil {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion client/pkg/testutil/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

type Action struct {
Name string
Params []interface{}
Params []any
}

type Recorder interface {
Expand Down
28 changes: 14 additions & 14 deletions client/pkg/testutil/testingtb.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ import (
// We cannot implement testing.TB due to protection, so we expose this simplified interface.
type TB interface {
Cleanup(func())
Error(args ...interface{})
Errorf(format string, args ...interface{})
Error(args ...any)
Errorf(format string, args ...any)
Fail()
FailNow()
Failed() bool
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Logf(format string, args ...interface{})
Fatal(args ...any)
Fatalf(format string, args ...any)
Logf(format string, args ...any)
Name() string
TempDir() string
Helper()
Skip(args ...interface{})
Skip(args ...any)
}

// NewTestingTBProthesis creates a fake variant of testing.TB implementation.
Expand All @@ -59,20 +59,20 @@ func (t *testingTBProthesis) Helper() {
// Ignored
}

func (t *testingTBProthesis) Skip(args ...interface{}) {
t.Log(append([]interface{}{"Skipping due to: "}, args...))
func (t *testingTBProthesis) Skip(args ...any) {
t.Log(append([]any{"Skipping due to: "}, args...))
}

func (t *testingTBProthesis) Cleanup(f func()) {
t.cleanups = append(t.cleanups, f)
}

func (t *testingTBProthesis) Error(args ...interface{}) {
func (t *testingTBProthesis) Error(args ...any) {
log.Println(args...)
t.Fail()
}

func (t *testingTBProthesis) Errorf(format string, args ...interface{}) {
func (t *testingTBProthesis) Errorf(format string, args ...any) {
log.Printf(format, args...)
t.Fail()
}
Expand All @@ -90,19 +90,19 @@ func (t *testingTBProthesis) Failed() bool {
return t.failed
}

func (t *testingTBProthesis) Fatal(args ...interface{}) {
func (t *testingTBProthesis) Fatal(args ...any) {
log.Fatalln(args...)
}

func (t *testingTBProthesis) Fatalf(format string, args ...interface{}) {
func (t *testingTBProthesis) Fatalf(format string, args ...any) {
log.Fatalf(format, args...)
}

func (t *testingTBProthesis) Logf(format string, args ...interface{}) {
func (t *testingTBProthesis) Logf(format string, args ...any) {
log.Printf(format, args...)
}

func (t *testingTBProthesis) Log(args ...interface{}) {
func (t *testingTBProthesis) Log(args ...any) {
log.Println(args...)
}

Expand Down
2 changes: 1 addition & 1 deletion client/pkg/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Verify(f func()) {
}

// Assert will panic with a given formatted message if the given condition is false.
func Assert(condition bool, msg string, v ...interface{}) {
func Assert(condition bool, msg string, v ...any) {
if !condition {
panic(fmt.Sprintf("assertion failed: "+msg, v...))
}
Expand Down
6 changes: 3 additions & 3 deletions client/v3/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (

type Cmp pb.Compare

func Compare(cmp Cmp, result string, v interface{}) Cmp {
func Compare(cmp Cmp, result string, v any) Cmp {
var r pb.Compare_CompareResult

switch result {
Expand Down Expand Up @@ -120,7 +120,7 @@ func (cmp Cmp) WithPrefix() Cmp {
}

// mustInt64 panics if val isn't an int or int64. It returns an int64 otherwise.
func mustInt64(val interface{}) int64 {
func mustInt64(val any) int64 {
if v, ok := val.(int64); ok {
return v
}
Expand All @@ -132,7 +132,7 @@ func mustInt64(val interface{}) int64 {

// mustInt64orLeaseID panics if val isn't a LeaseID, int or int64. It returns an
// int64 otherwise.
func mustInt64orLeaseID(val interface{}) int64 {
func mustInt64orLeaseID(val any) int64 {
if v, ok := val.(LeaseID); ok {
return int64(v)
}
Expand Down
2 changes: 1 addition & 1 deletion client/v3/naming/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Endpoint struct {
// Metadata is the information associated with Addr, which may be used
// to make load balancing decision.
// Since etcd 3.1
Metadata interface{}
Metadata any
}

type Operation uint8
Expand Down
2 changes: 1 addition & 1 deletion client/v3/naming/endpoints/internal/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ type Update struct {
// Metadata is the updated metadata. It is nil if there is no metadata update.
// Metadata is not required for a custom naming implementation.
// Since etcd 3.1.
Metadata interface{}
Metadata any
}
14 changes: 7 additions & 7 deletions client/v3/retry_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
// changed through options (e.g. WithMax) on creation of the interceptor or on call (through grpc.CallOptions).
func (c *Client) unaryClientInterceptor(optFuncs ...retryOption) grpc.UnaryClientInterceptor {
intOpts := reuseOrNewWithCallOptions(defaultOptions, optFuncs)
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 {
ctx = withVersion(ctx)
grpcOpts, retryOpts := filterCallOptions(opts)
callOpts := reuseOrNewWithCallOptions(intOpts, retryOpts)
Expand Down Expand Up @@ -179,9 +179,9 @@ func (c *Client) refreshToken(ctx context.Context) error {
type serverStreamingRetryingStream struct {
grpc.ClientStream
client *Client
bufferedSends []interface{} // single message that the client can sen
receivedGood bool // indicates whether any prior receives were successful
wasClosedSend bool // indicates that CloseSend was closed
bufferedSends []any // single message that the client can sen
receivedGood bool // indicates whether any prior receives were successful
wasClosedSend bool // indicates that CloseSend was closed
ctx context.Context
callOpts *options
streamerCall func(ctx context.Context) (grpc.ClientStream, error)
Expand All @@ -200,7 +200,7 @@ func (s *serverStreamingRetryingStream) getStream() grpc.ClientStream {
return s.ClientStream
}

func (s *serverStreamingRetryingStream) SendMsg(m interface{}) error {
func (s *serverStreamingRetryingStream) SendMsg(m any) error {
s.mu.Lock()
s.bufferedSends = append(s.bufferedSends, m)
s.mu.Unlock()
Expand All @@ -222,7 +222,7 @@ func (s *serverStreamingRetryingStream) Trailer() metadata.MD {
return s.getStream().Trailer()
}

func (s *serverStreamingRetryingStream) RecvMsg(m interface{}) error {
func (s *serverStreamingRetryingStream) RecvMsg(m any) error {
attemptRetry, lastErr := s.receiveMsgAndIndicateRetry(m)
if !attemptRetry {
return lastErr // success or hard failure
Expand All @@ -249,7 +249,7 @@ func (s *serverStreamingRetryingStream) RecvMsg(m interface{}) error {
return lastErr
}

func (s *serverStreamingRetryingStream) receiveMsgAndIndicateRetry(m interface{}) (bool, error) {
func (s *serverStreamingRetryingStream) receiveMsgAndIndicateRetry(m any) (bool, error) {
s.mu.RLock()
wasGood := s.receivedGood
s.mu.RUnlock()
Expand Down
4 changes: 2 additions & 2 deletions etcdctl/ctlv3/command/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func NewPrinter(printerType string, isHex bool) printer {

type printerRPC struct {
printer
p func(interface{})
p func(any)
}

func (p *printerRPC) Del(r v3.DeleteResponse) { p.p((*pb.DeleteRangeResponse)(&r)) }
Expand Down Expand Up @@ -159,7 +159,7 @@ func (p *printerRPC) AuthStatus(r v3.AuthStatusResponse) {
type printerUnsupported struct{ printerRPC }

func newPrinterUnsupported(n string) printer {
f := func(interface{}) {
f := func(any) {
cobrautl.ExitWithError(cobrautl.ExitBadFeature, errors.New(n+" not supported as output format"))
}
return &printerUnsupported{printerRPC{nil, f}}
Expand Down
2 changes: 1 addition & 1 deletion etcdctl/ctlv3/command/printer_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (p *jsonPrinter) MemberList(r clientv3.MemberListResponse) {
}
}

func printJSON(v interface{}) {
func printJSON(v any) {
b, err := json.Marshal(v)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion etcdctl/ctlv3/command/printer_protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (p *pbPrinter) Watch(r v3.WatchResponse) {
printPB(&wr)
}

func printPB(v interface{}) {
func printPB(v any) {
m, ok := v.(pbMarshal)
if !ok {
cobrautl.ExitWithError(cobrautl.ExitBadFeature, fmt.Errorf("marshal unsupported for type %T (%v)", v, v))
Expand Down
4 changes: 2 additions & 2 deletions etcdutl/etcdutl/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func NewPrinter(printerType string) printer {

type printerRPC struct {
printer
p func(interface{})
p func(any)
}

type printerUnsupported struct{ printerRPC }

func newPrinterUnsupported(n string) printer {
f := func(interface{}) {
f := func(any) {
cobrautl.ExitWithError(cobrautl.ExitBadFeature, errors.New(n+" not supported as output format"))
}
return &printerUnsupported{printerRPC{nil, f}}
Expand Down
2 changes: 1 addition & 1 deletion etcdutl/etcdutl/printer_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newJSONPrinter() printer {
func (p *jsonPrinter) DBStatus(r snapshot.Status) { printJSON(r) }

// !!! Share ??
func printJSON(v interface{}) {
func printJSON(v any) {
b, err := json.Marshal(v)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion etcdutl/etcdutl/printer_protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newPBPrinter() printer {
}
}

func printPB(v interface{}) {
func printPB(v any) {
m, ok := v.(pbMarshal)
if !ok {
cobrautl.ExitWithError(cobrautl.ExitBadFeature, fmt.Errorf("marshal unsupported for type %T (%v)", v, v))
Expand Down
8 changes: 4 additions & 4 deletions pkg/adt/interval_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ func (x *intervalNode) visit(iv *Interval, sentinel *intervalNode, nv nodeVisito
// IntervalValue represents a range tree node that contains a range and a value.
type IntervalValue struct {
Ivl Interval
Val interface{}
Val any
}

// IntervalTree represents a (mostly) textbook implementation of the
// "Introduction to Algorithms" (Cormen et al, 3rd ed.) chapter 13 red-black tree
// and chapter 14.3 interval tree with search supporting "stabbing queries".
type IntervalTree interface {
// Insert adds a node with the given interval into the tree.
Insert(ivl Interval, val interface{})
Insert(ivl Interval, val any)
// Delete removes the node with the given interval from the tree, returning
// true if a node is in fact removed.
Delete(ivl Interval) bool
Expand Down Expand Up @@ -423,7 +423,7 @@ func (ivt *intervalTree) deleteFixup(x *intervalNode) {
}
}

func (ivt *intervalTree) createIntervalNode(ivl Interval, val interface{}) *intervalNode {
func (ivt *intervalTree) createIntervalNode(ivl Interval, val any) *intervalNode {
return &intervalNode{
iv: IntervalValue{ivl, val},
max: ivl.End,
Expand Down Expand Up @@ -466,7 +466,7 @@ func (ivt *intervalTree) createIntervalNode(ivl Interval, val interface{}) *inte
// RB-INSERT-FIXUP(T, z)

// Insert adds a node with the given interval into the tree.
func (ivt *intervalTree) Insert(ivl Interval, val interface{}) {
func (ivt *intervalTree) Insert(ivl Interval, val any) {
y := ivt.sentinel
z := ivt.createIntervalNode(ivl, val)
x := ivt.root
Expand Down
2 changes: 1 addition & 1 deletion pkg/grpc_testing/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type RequestInfo struct {
}

func (ri *GrpcRecorder) UnaryInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
ri.record(toRequestInfo(ctx, info))
resp, err := handler(ctx, req)
return resp, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/traceutil/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
// Field is a kv pair to record additional details of the trace.
type Field struct {
Key string
Value interface{}
Value any
}

func (f *Field) format() string {
Expand Down
Loading

0 comments on commit 0917288

Please sign in to comment.