switch to stdlib context

This commit is contained in:
Asim Aslam 2018-03-03 11:53:52 +00:00
parent 982e6068cf
commit c9b40cb33b
42 changed files with 53 additions and 102 deletions

View File

@ -125,11 +125,11 @@ It does the following:
package main package main
import ( import (
"context"
"fmt" "fmt"
micro "github.com/micro/go-micro" micro "github.com/micro/go-micro"
proto "github.com/micro/examples/service/proto" proto "github.com/micro/examples/service/proto"
"golang.org/x/net/context"
) )
type Greeter struct{} type Greeter struct{}
@ -180,11 +180,11 @@ The generated proto includes a greeter client to reduce boilerplate code.
package main package main
import ( import (
"context"
"fmt" "fmt"
micro "github.com/micro/go-micro" micro "github.com/micro/go-micro"
proto "github.com/micro/examples/service/proto" proto "github.com/micro/examples/service/proto"
"golang.org/x/net/context"
) )
@ -230,9 +230,10 @@ A Function is a one time executing Service which exits after completing a reques
package main package main
import ( import (
"context"
proto "github.com/micro/examples/function/proto" proto "github.com/micro/examples/function/proto"
"github.com/micro/go-micro" "github.com/micro/go-micro"
"golang.org/x/net/context"
) )
type Greeter struct{} type Greeter struct{}

View File

@ -2,6 +2,7 @@ package broker
import ( import (
"bytes" "bytes"
"context"
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
@ -26,8 +27,6 @@ import (
mnet "github.com/micro/misc/lib/net" mnet "github.com/micro/misc/lib/net"
mls "github.com/micro/misc/lib/tls" mls "github.com/micro/misc/lib/tls"
"github.com/pborman/uuid" "github.com/pborman/uuid"
"golang.org/x/net/context"
) )
// HTTP Broker is a point to point async broker // HTTP Broker is a point to point async broker

View File

@ -1,11 +1,11 @@
package broker package broker
import ( import (
"context"
"crypto/tls" "crypto/tls"
"github.com/micro/go-micro/broker/codec" "github.com/micro/go-micro/broker/codec"
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"golang.org/x/net/context"
) )
type Options struct { type Options struct {

View File

@ -1,10 +1,9 @@
package client package client
import ( import (
"context"
"math" "math"
"time" "time"
"golang.org/x/net/context"
) )
type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error) type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error)

View File

@ -1,11 +1,10 @@
package client package client
import ( import (
"context"
"math" "math"
"testing" "testing"
"time" "time"
"golang.org/x/net/context"
) )
func TestBackoff(t *testing.T) { func TestBackoff(t *testing.T) {

View File

@ -2,9 +2,8 @@
package client package client
import ( import (
"context"
"time" "time"
"golang.org/x/net/context"
) )
// Client is the interface used to make requests to services. // Client is the interface used to make requests to services.

View File

@ -1,41 +1,7 @@
package client package client
/*
Wrapper is a type of middleware for the go-micro client. It allows
the client to be "wrapped" so that requests and responses can be intercepted
to perform extra requirements such as auth, tracing, monitoring, logging, etc.
Example usage:
import (
"log"
"github.com/micro/go-micro/client"
)
type LogWrapper struct {
client.Client
}
func (l *LogWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
log.Println("Making request to service " + req.Service() + " method " + req.Method())
return w.Client.Call(ctx, req, rsp)
}
func Wrapper(c client.Client) client.Client {
return &LogWrapper{c}
}
func main() {
c := client.NewClient(client.Wrap(Wrapper))
}
*/
import ( import (
"golang.org/x/net/context" "context"
) )
// CallFunc represents the individual call func // CallFunc represents the individual call func

View File

@ -1,7 +1,7 @@
package client package client
import ( import (
"golang.org/x/net/context" "context"
) )
type clientKey struct{} type clientKey struct{}

View File

@ -1,7 +1,7 @@
package mock package mock
import ( import (
"golang.org/x/net/context" "context"
) )
type responseKey struct{} type responseKey struct{}

View File

@ -1,14 +1,13 @@
package mock package mock
import ( import (
"context"
"fmt" "fmt"
"reflect" "reflect"
"sync" "sync"
"github.com/micro/go-micro/client" "github.com/micro/go-micro/client"
"github.com/micro/go-micro/errors" "github.com/micro/go-micro/errors"
"golang.org/x/net/context"
) )
var ( var (

View File

@ -1,11 +1,10 @@
package mock package mock
import ( import (
"context"
"testing" "testing"
"github.com/micro/go-micro/errors" "github.com/micro/go-micro/errors"
"golang.org/x/net/context"
) )
func TestClient(t *testing.T) { func TestClient(t *testing.T) {

View File

@ -1,6 +1,7 @@
package client package client
import ( import (
"context"
"time" "time"
"github.com/micro/go-micro/broker" "github.com/micro/go-micro/broker"
@ -8,8 +9,6 @@ import (
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"github.com/micro/go-micro/selector" "github.com/micro/go-micro/selector"
"github.com/micro/go-micro/transport" "github.com/micro/go-micro/transport"
"golang.org/x/net/context"
) )
type Options struct { type Options struct {

View File

@ -1,6 +1,8 @@
package client package client
import "golang.org/x/net/context" import (
"context"
)
// note that returning either false or a non-nil error will result in the call not being retried // note that returning either false or a non-nil error will result in the call not being retried
type RetryFunc func(ctx context.Context, req Request, retryCount int, err error) (bool, error) type RetryFunc func(ctx context.Context, req Request, retryCount int, err error) (bool, error)

View File

@ -2,6 +2,7 @@ package client
import ( import (
"bytes" "bytes"
"context"
"fmt" "fmt"
"sync" "sync"
"time" "time"
@ -12,8 +13,6 @@ import (
"github.com/micro/go-micro/metadata" "github.com/micro/go-micro/metadata"
"github.com/micro/go-micro/selector" "github.com/micro/go-micro/selector"
"github.com/micro/go-micro/transport" "github.com/micro/go-micro/transport"
"golang.org/x/net/context"
) )
type rpcClient struct { type rpcClient struct {

View File

@ -1,14 +1,13 @@
package client package client
import ( import (
"context"
"fmt" "fmt"
"testing" "testing"
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"github.com/micro/go-micro/registry/mock" "github.com/micro/go-micro/registry/mock"
"github.com/micro/go-micro/selector" "github.com/micro/go-micro/selector"
"golang.org/x/net/context"
) )
func TestCallWrapper(t *testing.T) { func TestCallWrapper(t *testing.T) {

View File

@ -1,10 +1,9 @@
package client package client
import ( import (
"context"
"io" "io"
"sync" "sync"
"golang.org/x/net/context"
) )
// Implements the streamer interface // Implements the streamer interface

View File

@ -1,14 +1,14 @@
package cmd package cmd
import ( import (
"context"
"github.com/micro/go-micro/broker" "github.com/micro/go-micro/broker"
"github.com/micro/go-micro/client" "github.com/micro/go-micro/client"
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"github.com/micro/go-micro/selector" "github.com/micro/go-micro/selector"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
"github.com/micro/go-micro/transport" "github.com/micro/go-micro/transport"
"golang.org/x/net/context"
) )
type Options struct { type Options struct {

View File

@ -1,10 +1,10 @@
package micro package micro
import ( import (
"context"
"time" "time"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
"golang.org/x/net/context"
) )
type function struct { type function struct {

View File

@ -1,13 +1,12 @@
package micro package micro
import ( import (
"context"
"sync" "sync"
"testing" "testing"
"github.com/micro/go-micro/registry/mock" "github.com/micro/go-micro/registry/mock"
proto "github.com/micro/go-micro/server/debug/proto" proto "github.com/micro/go-micro/server/debug/proto"
"golang.org/x/net/context"
) )
func TestFunction(t *testing.T) { func TestFunction(t *testing.T) {

View File

@ -2,10 +2,10 @@
package micro package micro
import ( import (
"context"
"github.com/micro/go-micro/client" "github.com/micro/go-micro/client"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
"golang.org/x/net/context"
) )
type serviceKey struct{} type serviceKey struct{}

View File

@ -2,7 +2,7 @@
package metadata package metadata
import ( import (
"golang.org/x/net/context" "context"
) )
type metaKey struct{} type metaKey struct{}

View File

@ -1,9 +1,8 @@
package metadata package metadata
import ( import (
"context"
"testing" "testing"
"golang.org/x/net/context"
) )
func TestMetadataContext(t *testing.T) { func TestMetadataContext(t *testing.T) {

View File

@ -1,6 +1,7 @@
package micro package micro
import ( import (
"context"
"time" "time"
"github.com/micro/cli" "github.com/micro/cli"
@ -11,8 +12,6 @@ import (
"github.com/micro/go-micro/selector" "github.com/micro/go-micro/selector"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
"github.com/micro/go-micro/transport" "github.com/micro/go-micro/transport"
"golang.org/x/net/context"
) )
type Options struct { type Options struct {

View File

@ -1,8 +1,9 @@
package micro package micro
import ( import (
"context"
"github.com/micro/go-micro/client" "github.com/micro/go-micro/client"
"golang.org/x/net/context"
) )
type publisher struct { type publisher struct {

View File

@ -1,9 +1,10 @@
package consul package consul
import ( import (
"context"
consul "github.com/hashicorp/consul/api" consul "github.com/hashicorp/consul/api"
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"golang.org/x/net/context"
) )
func Config(c *consul.Config) registry.Option { func Config(c *consul.Config) registry.Option {

View File

@ -1,10 +1,9 @@
package registry package registry
import ( import (
"context"
"crypto/tls" "crypto/tls"
"time" "time"
"golang.org/x/net/context"
) )
type Options struct { type Options struct {

View File

@ -1,10 +1,10 @@
package cache package cache
import ( import (
"context"
"time" "time"
"github.com/micro/go-micro/selector" "github.com/micro/go-micro/selector"
"golang.org/x/net/context"
) )
type ttlKey struct{} type ttlKey struct{}

View File

@ -1,9 +1,9 @@
package selector package selector
import ( import (
"github.com/micro/go-micro/registry" "context"
"golang.org/x/net/context" "github.com/micro/go-micro/registry"
) )
type Options struct { type Options struct {

View File

@ -1,7 +1,7 @@
package server package server
import ( import (
"golang.org/x/net/context" "context"
) )
type serverKey struct{} type serverKey struct{}

View File

@ -1,12 +1,11 @@
package debug package debug
import ( import (
"context"
"runtime" "runtime"
"time" "time"
proto "github.com/micro/go-micro/server/debug/proto" proto "github.com/micro/go-micro/server/debug/proto"
"golang.org/x/net/context"
) )
// The debug handler represents an internal server handler // The debug handler represents an internal server handler

View File

@ -1,11 +1,11 @@
package server package server
import ( import (
"context"
"reflect" "reflect"
"testing" "testing"
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"golang.org/x/net/context"
) )
type testHandler struct{} type testHandler struct{}

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"context"
"time" "time"
"github.com/micro/go-micro/broker" "github.com/micro/go-micro/broker"
@ -8,8 +9,6 @@ import (
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"github.com/micro/go-micro/server/debug" "github.com/micro/go-micro/server/debug"
"github.com/micro/go-micro/transport" "github.com/micro/go-micro/transport"
"golang.org/x/net/context"
) )
type Options struct { type Options struct {

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"context"
"fmt" "fmt"
"runtime/debug" "runtime/debug"
"sort" "sort"
@ -17,8 +18,6 @@ import (
"github.com/micro/go-micro/transport" "github.com/micro/go-micro/transport"
"github.com/micro/misc/lib/addr" "github.com/micro/misc/lib/addr"
"golang.org/x/net/context"
) )
type rpcServer struct { type rpcServer struct {

View File

@ -7,6 +7,7 @@ package server
// Meh, we need to get rid of this shit // Meh, we need to get rid of this shit
import ( import (
"context"
"errors" "errors"
"io" "io"
"reflect" "reflect"
@ -16,7 +17,6 @@ import (
"unicode/utf8" "unicode/utf8"
"github.com/micro/go-log" "github.com/micro/go-log"
"golang.org/x/net/context"
) )
var ( var (

View File

@ -1,9 +1,8 @@
package server package server
import ( import (
"context"
"sync" "sync"
"golang.org/x/net/context"
) )
// Implements the Streamer interface // Implements the Streamer interface

View File

@ -2,13 +2,13 @@
package server package server
import ( import (
"context"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"github.com/micro/go-log" "github.com/micro/go-log"
"github.com/pborman/uuid" "github.com/pborman/uuid"
"golang.org/x/net/context"
) )
type Server interface { type Server interface {

View File

@ -1,7 +1,7 @@
package server package server
import ( import (
"golang.org/x/net/context" "context"
) )
// HandlerFunc represents a single method of a handler. It's used primarily // HandlerFunc represents a single method of a handler. It's used primarily

View File

@ -2,6 +2,7 @@ package server
import ( import (
"bytes" "bytes"
"context"
"fmt" "fmt"
"reflect" "reflect"
@ -9,7 +10,6 @@ import (
"github.com/micro/go-micro/codec" "github.com/micro/go-micro/codec"
"github.com/micro/go-micro/metadata" "github.com/micro/go-micro/metadata"
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"golang.org/x/net/context"
) )
const ( const (

View File

@ -1,13 +1,12 @@
package micro package micro
import ( import (
"context"
"sync" "sync"
"testing" "testing"
"github.com/micro/go-micro/registry/mock" "github.com/micro/go-micro/registry/mock"
proto "github.com/micro/go-micro/server/debug/proto" proto "github.com/micro/go-micro/server/debug/proto"
"golang.org/x/net/context"
) )
func TestService(t *testing.T) { func TestService(t *testing.T) {

View File

@ -1,11 +1,11 @@
package transport package transport
import ( import (
"context"
"crypto/tls" "crypto/tls"
"time" "time"
"github.com/micro/go-micro/transport/codec" "github.com/micro/go-micro/transport/codec"
"golang.org/x/net/context"
) )
type Options struct { type Options struct {

View File

@ -1,10 +1,10 @@
package micro package micro
import ( import (
"context"
"github.com/micro/go-micro/client" "github.com/micro/go-micro/client"
"github.com/micro/go-micro/metadata" "github.com/micro/go-micro/metadata"
"golang.org/x/net/context"
) )
type clientWrapper struct { type clientWrapper struct {

View File

@ -1,11 +1,10 @@
package micro package micro
import ( import (
"context"
"testing" "testing"
"github.com/micro/go-micro/metadata" "github.com/micro/go-micro/metadata"
"golang.org/x/net/context"
) )
func TestWrapper(t *testing.T) { func TestWrapper(t *testing.T) {