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 <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2018-04-23 18:50:30 -07:00
parent f337075620
commit 9d0d4b806c
3 changed files with 6 additions and 9 deletions

View File

@ -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() {

View File

@ -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 {

View File

@ -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 {