Use any instead of interface{}
Signed-off-by: chenyahui <cyhone@qq.com>
This commit is contained in:
@ -523,7 +523,7 @@ func TestClusterAddMember(t *testing.T) {
|
||||
wactions := []testutil.Action{
|
||||
{
|
||||
Name: "Create",
|
||||
Params: []interface{}{
|
||||
Params: []any{
|
||||
path.Join(StoreMembersPrefix, "1", "raftAttributes"),
|
||||
false,
|
||||
`{"peerURLs":null}`,
|
||||
@ -546,7 +546,7 @@ func TestClusterAddMemberAsLearner(t *testing.T) {
|
||||
wactions := []testutil.Action{
|
||||
{
|
||||
Name: "Create",
|
||||
Params: []interface{}{
|
||||
Params: []any{
|
||||
path.Join(StoreMembersPrefix, "1", "raftAttributes"),
|
||||
false,
|
||||
`{"peerURLs":null,"isLearner":true}`,
|
||||
@ -587,8 +587,8 @@ func TestClusterRemoveMember(t *testing.T) {
|
||||
c.RemoveMember(1, true)
|
||||
|
||||
wactions := []testutil.Action{
|
||||
{Name: "Delete", Params: []interface{}{MemberStoreKey(1), true, true}},
|
||||
{Name: "Create", Params: []interface{}{RemovedMemberStoreKey(1), false, "", false, v2store.TTLOptionSet{ExpireTime: v2store.Permanent}}},
|
||||
{Name: "Delete", Params: []any{MemberStoreKey(1), true, true}},
|
||||
{Name: "Create", Params: []any{RemovedMemberStoreKey(1), false, "", false, v2store.TTLOptionSet{ExpireTime: v2store.Permanent}}},
|
||||
}
|
||||
if !reflect.DeepEqual(st.Action(), wactions) {
|
||||
t.Errorf("actions = %v, want %v", st.Action(), wactions)
|
||||
|
@ -276,7 +276,7 @@ func (t *respRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
if t.rec != nil {
|
||||
t.rec.Record(testutil.Action{Name: "req", Params: []interface{}{req}})
|
||||
t.rec.Record(testutil.Action{Name: "req", Params: []any{req}})
|
||||
}
|
||||
return &http.Response{StatusCode: t.code, Header: t.header, Body: &nopReadCloser{}}, t.err
|
||||
}
|
||||
@ -287,7 +287,7 @@ type roundTripperRecorder struct {
|
||||
|
||||
func (t *roundTripperRecorder) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if t.rec != nil {
|
||||
t.rec.Record(testutil.Action{Name: "req", Params: []interface{}{req}})
|
||||
t.rec.Record(testutil.Action{Name: "req", Params: []any{req}})
|
||||
}
|
||||
return &http.Response{StatusCode: http.StatusNoContent, Body: &nopReadCloser{}}, nil
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ func BenchmarkWatchOneKey(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func benchStoreSet(b *testing.B, valueSize int, process func(interface{}) ([]byte, error)) {
|
||||
func benchStoreSet(b *testing.B, valueSize int, process func(any) ([]byte, error)) {
|
||||
s := newStore()
|
||||
b.StopTimer()
|
||||
kvs, size := generateNRandomKV(b.N, valueSize)
|
||||
|
@ -45,13 +45,13 @@ func (h ttlKeyHeap) Swap(i, j int) {
|
||||
h.keyMap[h.array[j]] = j
|
||||
}
|
||||
|
||||
func (h *ttlKeyHeap) Push(x interface{}) {
|
||||
func (h *ttlKeyHeap) Push(x any) {
|
||||
n, _ := x.(*node)
|
||||
h.keyMap[n] = len(h.array)
|
||||
h.array = append(h.array, n)
|
||||
}
|
||||
|
||||
func (h *ttlKeyHeap) Pop() interface{} {
|
||||
func (h *ttlKeyHeap) Pop() any {
|
||||
old := h.array
|
||||
n := len(old)
|
||||
x := old[n-1]
|
||||
@ -77,7 +77,7 @@ func (h *ttlKeyHeap) pop() *node {
|
||||
return n
|
||||
}
|
||||
|
||||
func (h *ttlKeyHeap) push(x interface{}) {
|
||||
func (h *ttlKeyHeap) push(x any) {
|
||||
heap.Push(h, x)
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ type fakeCompactable struct {
|
||||
}
|
||||
|
||||
func (fc *fakeCompactable) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) {
|
||||
fc.Record(testutil.Action{Name: "c", Params: []interface{}{r}})
|
||||
fc.Record(testutil.Action{Name: "c", Params: []any{r}})
|
||||
return &pb.CompactionResponse{}, nil
|
||||
}
|
||||
|
||||
|
@ -18,13 +18,13 @@ import "github.com/golang/protobuf/proto"
|
||||
|
||||
type codec struct{}
|
||||
|
||||
func (c *codec) Marshal(v interface{}) ([]byte, error) {
|
||||
func (c *codec) Marshal(v any) ([]byte, error) {
|
||||
b, err := proto.Marshal(v.(proto.Message))
|
||||
sentBytes.Add(float64(len(b)))
|
||||
return b, err
|
||||
}
|
||||
|
||||
func (c *codec) Unmarshal(data []byte, v interface{}) error {
|
||||
func (c *codec) Unmarshal(data []byte, v any) error {
|
||||
receivedBytes.Add(float64(len(data)))
|
||||
return proto.Unmarshal(data, v.(proto.Message))
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ type streamsMap struct {
|
||||
}
|
||||
|
||||
func newUnaryInterceptor(s *etcdserver.EtcdServer) 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) {
|
||||
if !api.IsCapabilityEnabled(api.V3rpcCapability) {
|
||||
return nil, rpctypes.ErrGRPCNotCapable
|
||||
}
|
||||
@ -77,7 +77,7 @@ func newUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerInterceptor {
|
||||
}
|
||||
|
||||
func newLogUnaryInterceptor(s *etcdserver.EtcdServer) 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) {
|
||||
startTime := time.Now()
|
||||
resp, err := handler(ctx, req)
|
||||
lg := s.Logger()
|
||||
@ -88,7 +88,7 @@ func newLogUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerIntercepto
|
||||
}
|
||||
}
|
||||
|
||||
func logUnaryRequestStats(ctx context.Context, lg *zap.Logger, warnLatency time.Duration, info *grpc.UnaryServerInfo, startTime time.Time, req interface{}, resp interface{}) {
|
||||
func logUnaryRequestStats(ctx context.Context, lg *zap.Logger, warnLatency time.Duration, info *grpc.UnaryServerInfo, startTime time.Time, req any, resp any) {
|
||||
duration := time.Since(startTime)
|
||||
var enabledDebugLevel, expensiveRequest bool
|
||||
if lg.Core().Enabled(zap.DebugLevel) {
|
||||
@ -214,7 +214,7 @@ func logExpensiveRequestStats(lg *zap.Logger, startTime time.Time, duration time
|
||||
func newStreamInterceptor(s *etcdserver.EtcdServer) grpc.StreamServerInterceptor {
|
||||
smap := monitorLeader(s)
|
||||
|
||||
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
||||
return func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
||||
if !api.IsCapabilityEnabled(api.V3rpcCapability) {
|
||||
return rpctypes.ErrGRPCNotCapable
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ type quotaAlarmer struct {
|
||||
|
||||
// check whether request satisfies the quota. If there is not enough space,
|
||||
// ignore request and raise the free space alarm.
|
||||
func (qa *quotaAlarmer) check(ctx context.Context, r interface{}) error {
|
||||
func (qa *quotaAlarmer) check(ctx context.Context, r any) error {
|
||||
if qa.q.Available(r) {
|
||||
return nil
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ func isClientCtxErr(ctxErr error, err error) bool {
|
||||
}
|
||||
|
||||
// in v3.4, learner is allowed to serve serializable read and endpoint status
|
||||
func isRPCSupportedForLearner(req interface{}) bool {
|
||||
func isRPCSupportedForLearner(req any) bool {
|
||||
switch r := req.(type) {
|
||||
case *pb.StatusRequest:
|
||||
return true
|
||||
|
Reference in New Issue
Block a user