avoid "any" as variable name

Avoid shadowing / confusion with Go's "any" built-in type.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2023-06-10 13:49:06 +02:00
parent ee2c8b79bf
commit 4bb709c018
25 changed files with 82 additions and 83 deletions

View File

@@ -143,12 +143,12 @@ func (c *criService) updateContainerResources(ctx context.Context,
// updateContainerSpec updates container spec.
func updateContainerSpec(ctx context.Context, cntr containerd.Container, spec *runtimespec.Spec) error {
any, err := typeurl.MarshalAny(spec)
s, err := typeurl.MarshalAny(spec)
if err != nil {
return fmt.Errorf("failed to marshal spec %+v: %w", spec, err)
}
if err := cntr.Update(ctx, func(ctx gocontext.Context, client *containerd.Client, c *containers.Container) error {
c.Spec = any
c.Spec = s
return nil
}); err != nil {
return fmt.Errorf("failed to update container spec: %w", err)

View File

@@ -281,9 +281,9 @@ func (em *eventMonitor) start() <-chan error {
ids := em.backOff.getExpiredIDs()
for _, id := range ids {
queue := em.backOff.deBackOff(id)
for i, any := range queue.events {
if err := em.handleEvent(any); err != nil {
log.L.WithError(err).Errorf("Failed to handle backOff event %+v for %s", any, id)
for i, evt := range queue.events {
if err := em.handleEvent(evt); err != nil {
log.L.WithError(err).Errorf("Failed to handle backOff event %+v for %s", evt, id)
em.backOff.reBackOff(id, queue.events[i:], queue.duration)
break
}

View File

@@ -80,9 +80,9 @@ func TestBackOff(t *testing.T) {
t.Logf("Should be able to check if the container is in backOff state")
for k, queue := range inputQueues {
for _, e := range queue.events {
any, err := typeurl.MarshalAny(e)
evt, err := typeurl.MarshalAny(e)
assert.NoError(t, err)
key, _, err := convertEvent(any)
key, _, err := convertEvent(evt)
assert.NoError(t, err)
assert.Equal(t, k, key)
assert.Equal(t, actual.isInBackOff(key), true)

View File

@@ -159,9 +159,9 @@ func TestTypeurlMarshalUnmarshalSandboxMeta(t *testing.T) {
test.configChange(meta.Config)
}
any, err := typeurl.MarshalAny(meta)
md, err := typeurl.MarshalAny(meta)
assert.NoError(t, err)
data, err := typeurl.UnmarshalAny(any)
data, err := typeurl.UnmarshalAny(md)
assert.NoError(t, err)
assert.IsType(t, &sandboxstore.Metadata{}, data)
curMeta, ok := data.(*sandboxstore.Metadata)

View File

@@ -142,12 +142,12 @@ func (c *criService) updateContainerResources(ctx context.Context,
// updateContainerSpec updates container spec.
func updateContainerSpec(ctx context.Context, cntr containerd.Container, spec *runtimespec.Spec) error {
any, err := typeurl.MarshalAny(spec)
s, err := typeurl.MarshalAny(spec)
if err != nil {
return fmt.Errorf("failed to marshal spec %+v: %w", spec, err)
}
if err := cntr.Update(ctx, func(ctx gocontext.Context, client *containerd.Client, c *containers.Container) error {
c.Spec = any
c.Spec = s
return nil
}); err != nil {
return fmt.Errorf("failed to update container spec: %w", err)

View File

@@ -282,9 +282,9 @@ func (em *eventMonitor) start() <-chan error {
ids := em.backOff.getExpiredIDs()
for _, id := range ids {
queue := em.backOff.deBackOff(id)
for i, any := range queue.events {
if err := em.handleEvent(any); err != nil {
logrus.WithError(err).Errorf("Failed to handle backOff event %+v for %s", any, id)
for i, evt := range queue.events {
if err := em.handleEvent(evt); err != nil {
logrus.WithError(err).Errorf("Failed to handle backOff event %+v for %s", evt, id)
em.backOff.reBackOff(id, queue.events[i:], queue.duration)
break
}

View File

@@ -80,9 +80,9 @@ func TestBackOff(t *testing.T) {
t.Logf("Should be able to check if the container is in backOff state")
for k, queue := range inputQueues {
for _, e := range queue.events {
any, err := typeurl.MarshalAny(e)
evt, err := typeurl.MarshalAny(e)
assert.NoError(t, err)
key, _, err := convertEvent(any)
key, _, err := convertEvent(evt)
assert.NoError(t, err)
assert.Equal(t, k, key)
assert.Equal(t, actual.isInBackOff(key), true)

View File

@@ -162,9 +162,9 @@ func TestTypeurlMarshalUnmarshalSandboxMeta(t *testing.T) {
test.configChange(meta.Config)
}
any, err := typeurl.MarshalAny(meta)
md, err := typeurl.MarshalAny(meta)
assert.NoError(t, err)
data, err := typeurl.UnmarshalAny(any)
data, err := typeurl.UnmarshalAny(md)
assert.NoError(t, err)
assert.IsType(t, &sandboxstore.Metadata{}, data)
curMeta, ok := data.(*sandboxstore.Metadata)

View File

@@ -144,9 +144,9 @@ func (iis *ImageExportStream) MarshalAny(ctx context.Context, sm streaming.Strea
return typeurl.MarshalAny(s)
}
func (iis *ImageExportStream) UnmarshalAny(ctx context.Context, sm streaming.StreamGetter, any typeurl.Any) error {
func (iis *ImageExportStream) UnmarshalAny(ctx context.Context, sm streaming.StreamGetter, anyType typeurl.Any) error {
var s transfertypes.ImageExportStream
if err := typeurl.UnmarshalTo(any, &s); err != nil {
if err := typeurl.UnmarshalTo(anyType, &s); err != nil {
return err
}

View File

@@ -84,9 +84,9 @@ func (iis *ImageImportStream) MarshalAny(ctx context.Context, sm streaming.Strea
return typeurl.MarshalAny(s)
}
func (iis *ImageImportStream) UnmarshalAny(ctx context.Context, sm streaming.StreamGetter, any typeurl.Any) error {
func (iis *ImageImportStream) UnmarshalAny(ctx context.Context, sm streaming.StreamGetter, anyType typeurl.Any) error {
var s transferapi.ImageImportStream
if err := typeurl.UnmarshalTo(any, &s); err != nil {
if err := typeurl.UnmarshalTo(anyType, &s); err != nil {
return err
}

View File

@@ -261,11 +261,11 @@ func (cc *credCallback) GetCredentials(ctx context.Context, ref, host string) (C
Host: host,
Reference: ref,
}
any, err := typeurl.MarshalAny(ar)
anyType, err := typeurl.MarshalAny(ar)
if err != nil {
return Credentials{}, err
}
if err := cc.stream.Send(any); err != nil {
if err := cc.stream.Send(anyType); err != nil {
return Credentials{}, err
}
resp, err := cc.stream.Recv()

View File

@@ -53,14 +53,14 @@ func SendStream(ctx context.Context, r io.Reader, stream streaming.Stream) {
default:
}
any, err := stream.Recv()
anyType, err := stream.Recv()
if err != nil {
if !errors.Is(err, io.EOF) && !errors.Is(err, context.Canceled) {
log.G(ctx).WithError(err).Error("send stream ended without EOF")
}
return
}
i, err := typeurl.UnmarshalAny(any)
i, err := typeurl.UnmarshalAny(anyType)
if err != nil {
log.G(ctx).WithError(err).Error("failed to unmarshal stream object")
continue
@@ -124,13 +124,13 @@ func SendStream(ctx context.Context, r io.Reader, stream streaming.Stream) {
data := &transferapi.Data{
Data: b[:n],
}
any, err := typeurl.MarshalAny(data)
anyType, err := typeurl.MarshalAny(data)
if err != nil {
log.G(ctx).WithError(err).Errorf("failed to marshal data for send")
// TODO: Send error message on stream before close to allow remote side to return error
return
}
if err := stream.Send(any); err != nil {
if err := stream.Send(anyType); err != nil {
log.G(ctx).WithError(err).Errorf("send failed")
return
}
@@ -149,20 +149,20 @@ func ReceiveStream(ctx context.Context, stream streaming.Stream) io.Reader {
update := &transferapi.WindowUpdate{
Update: windowSize,
}
any, err := typeurl.MarshalAny(update)
anyType, err := typeurl.MarshalAny(update)
if err != nil {
w.CloseWithError(fmt.Errorf("failed to marshal window update: %w", err))
return
}
// check window update error after recv, stream may be complete
if werr = stream.Send(any); werr == nil {
if werr = stream.Send(anyType); werr == nil {
window += windowSize
} else if errors.Is(werr, io.EOF) {
// TODO: Why does send return EOF here
werr = nil
}
}
any, err := stream.Recv()
anyType, err := stream.Recv()
if err != nil {
if errors.Is(err, io.EOF) {
err = nil
@@ -176,7 +176,7 @@ func ReceiveStream(ctx context.Context, stream streaming.Stream) io.Reader {
w.CloseWithError(fmt.Errorf("failed to send window update: %w", werr))
return
}
i, err := typeurl.UnmarshalAny(any)
i, err := typeurl.UnmarshalAny(anyType)
if err != nil {
w.CloseWithError(fmt.Errorf("failed to unmarshal received object: %w", err))
return

View File

@@ -42,14 +42,14 @@ func WriteByteStream(ctx context.Context, stream streaming.Stream) io.WriteClose
default:
}
any, err := stream.Recv()
anyType, err := stream.Recv()
if err != nil {
if !errors.Is(err, io.EOF) && !errors.Is(err, context.Canceled) {
log.G(ctx).WithError(err).Error("send byte stream ended without EOF")
}
return
}
i, err := typeurl.UnmarshalAny(any)
i, err := typeurl.UnmarshalAny(anyType)
if err != nil {
log.G(ctx).WithError(err).Error("failed to unmarshal stream object")
continue
@@ -102,19 +102,19 @@ func (wbs *writeByteStream) Write(p []byte) (n int, err error) {
max = remaining
}
// TODO: continue
//remaining = remaining - int32(n)
// remaining = remaining - int32(n)
data := &transferapi.Data{
Data: p[:max],
}
var any typeurl.Any
any, err = typeurl.MarshalAny(data)
var anyType typeurl.Any
anyType, err = typeurl.MarshalAny(data)
if err != nil {
log.G(wbs.ctx).WithError(err).Errorf("failed to marshal data for send")
// TODO: Send error message on stream before close to allow remote side to return error
return
}
if err = wbs.stream.Send(any); err != nil {
if err = wbs.stream.Send(anyType); err != nil {
log.G(wbs.ctx).WithError(err).Errorf("send failed")
return
}