From 9d0d4b806c30b1fbba4a86debab2dded5faedc8f Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 23 Apr 2018 18:50:30 -0700 Subject: [PATCH] context pkg: untangle Since Go 1.7, "context" is a standard package, superceding the "x/net/context". Since Go 1.9, the latter only provides type aliases from the former. Therefore, it makes sense to switch to the standard package, and the change is not disruptive in any sense. This commit deals with a few cases where both packages happened to be imported by the same source file. A choice between "context" and "gocontext" was made for each file in order to minimize the patch. Signed-off-by: Kir Kolyshkin --- cmd/containerd/command/main.go | 5 ++--- services/images/local.go | 5 ++--- services/snapshots/service.go | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/cmd/containerd/command/main.go b/cmd/containerd/command/main.go index 274135757..8fba0fa38 100644 --- a/cmd/containerd/command/main.go +++ b/cmd/containerd/command/main.go @@ -17,7 +17,7 @@ package command import ( - "context" + gocontext "context" "fmt" "io/ioutil" golog "log" @@ -35,7 +35,6 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli" - gocontext "golang.org/x/net/context" "google.golang.org/grpc/grpclog" ) @@ -168,7 +167,7 @@ func App() *cli.App { return app } -func serve(ctx context.Context, l net.Listener, serveFunc func(net.Listener) error) { +func serve(ctx gocontext.Context, l net.Listener, serveFunc func(net.Listener) error) { path := l.Addr().String() log.G(ctx).WithField("address", path).Info("serving...") go func() { diff --git a/services/images/local.go b/services/images/local.go index 1cca1a42a..116c4e432 100644 --- a/services/images/local.go +++ b/services/images/local.go @@ -17,7 +17,7 @@ package images import ( - gocontext "context" + "context" eventstypes "github.com/containerd/containerd/api/events" imagesapi "github.com/containerd/containerd/api/services/images/v1" @@ -30,7 +30,6 @@ import ( "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/services" ptypes "github.com/gogo/protobuf/types" - "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -64,7 +63,7 @@ func init() { } type gcScheduler interface { - ScheduleAndWait(gocontext.Context) (gc.Stats, error) + ScheduleAndWait(context.Context) (gc.Stats, error) } type local struct { diff --git a/services/snapshots/service.go b/services/snapshots/service.go index 1d10fae1e..8ef7a47f5 100644 --- a/services/snapshots/service.go +++ b/services/snapshots/service.go @@ -17,7 +17,7 @@ package snapshots import ( - gocontext "context" + "context" snapshotsapi "github.com/containerd/containerd/api/services/snapshots/v1" "github.com/containerd/containerd/api/types" @@ -29,7 +29,6 @@ import ( "github.com/containerd/containerd/snapshots" ptypes "github.com/gogo/protobuf/types" "github.com/pkg/errors" - "golang.org/x/net/context" "google.golang.org/grpc" ) @@ -216,7 +215,7 @@ func (s *service) List(sr *snapshotsapi.ListSnapshotsRequest, ss snapshotsapi.Sn }) } ) - err = sn.Walk(ss.Context(), func(ctx gocontext.Context, info snapshots.Info) error { + err = sn.Walk(ss.Context(), func(ctx context.Context, info snapshots.Info) error { buffer = append(buffer, fromInfo(info)) if len(buffer) >= 100 {