v3 refactor (#1868)

* Move to v3

Co-authored-by: Ben Toogood <bentoogood@gmail.com>
This commit is contained in:
Asim Aslam
2020-07-27 13:22:00 +01:00
committed by GitHub
parent 9dfeb98111
commit 563768b58a
424 changed files with 6383 additions and 22490 deletions

View File

@@ -4,8 +4,8 @@ import (
"time"
"github.com/google/uuid"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/logger"
"github.com/micro/go-micro/v3/auth"
"github.com/micro/go-micro/v3/logger"
)
// Verify the auth credentials and refresh the auth token periodically

View File

@@ -6,7 +6,7 @@ import (
"net/textproto"
"strings"
"github.com/micro/go-micro/v2/metadata"
"github.com/micro/go-micro/v3/metadata"
)
func FromRequest(r *http.Request) context.Context {

View File

@@ -4,7 +4,7 @@ import (
"net/http"
"testing"
"github.com/micro/go-micro/v2/metadata"
"github.com/micro/go-micro/v3/metadata"
)
func TestRequestToContext(t *testing.T) {

View File

@@ -9,8 +9,8 @@ import (
"log"
"os"
"github.com/micro/go-micro/v2/client"
proto "github.com/micro/go-micro/v2/util/file/proto"
"github.com/micro/go-micro/v3/client"
proto "github.com/micro/go-micro/v3/util/file/proto"
)
// Client is the client interface to access files

View File

@@ -6,10 +6,10 @@ import (
"path/filepath"
"sync"
"github.com/micro/go-micro/v2/errors"
"github.com/micro/go-micro/v2/logger"
"github.com/micro/go-micro/v2/server"
proto "github.com/micro/go-micro/v2/util/file/proto"
"github.com/micro/go-micro/v3/errors"
"github.com/micro/go-micro/v3/logger"
"github.com/micro/go-micro/v3/server"
proto "github.com/micro/go-micro/v3/util/file/proto"
"golang.org/x/net/context"
)

View File

@@ -11,9 +11,9 @@ import (
import (
context "context"
api "github.com/micro/go-micro/v2/api"
client "github.com/micro/go-micro/v2/client"
server "github.com/micro/go-micro/v2/server"
api "github.com/micro/go-micro/v3/api"
client "github.com/micro/go-micro/v3/client"
server "github.com/micro/go-micro/v3/server"
)
// Reference imports to suppress errors if they are not otherwise used.

View File

@@ -8,9 +8,9 @@ import (
"net/http"
"strings"
"github.com/micro/go-micro/v2/metadata"
"github.com/micro/go-micro/v2/router"
"github.com/micro/go-micro/v2/selector/random"
"github.com/micro/go-micro/v3/metadata"
"github.com/micro/go-micro/v3/router/registry"
"github.com/micro/go-micro/v3/selector/random"
)
// Write sets the status and body on a http ResponseWriter
@@ -47,7 +47,7 @@ func WriteInternalServerError(w http.ResponseWriter, err error) {
func NewRoundTripper(opts ...Option) http.RoundTripper {
options := Options{
Router: router.DefaultRouter,
Router: registry.NewRouter(),
}
for _, o := range opts {
o(&options)

View File

@@ -6,10 +6,10 @@ import (
"net/http"
"testing"
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v2/registry/memory"
"github.com/micro/go-micro/v2/router"
regRouter "github.com/micro/go-micro/v2/router/registry"
"github.com/micro/go-micro/v3/registry"
"github.com/micro/go-micro/v3/registry/memory"
"github.com/micro/go-micro/v3/router"
regRouter "github.com/micro/go-micro/v3/router/registry"
)
func TestRoundTripper(t *testing.T) {

View File

@@ -1,6 +1,6 @@
package http
import "github.com/micro/go-micro/v2/router"
import "github.com/micro/go-micro/v3/router"
type Options struct {
Router router.Router

View File

@@ -4,8 +4,8 @@ import (
"errors"
"net/http"
"github.com/micro/go-micro/v2/router"
"github.com/micro/go-micro/v2/selector"
"github.com/micro/go-micro/v3/router"
"github.com/micro/go-micro/v3/selector"
)
type roundTripper struct {

View File

@@ -4,7 +4,7 @@ package io
import (
"io"
"github.com/micro/go-micro/v2/transport"
"github.com/micro/go-micro/v3/transport"
)
type rwc struct {

View File

@@ -10,7 +10,7 @@ import (
"net/http"
"net/url"
"github.com/micro/go-micro/v2/logger"
"github.com/micro/go-micro/v3/logger"
)
// Request is used to construct a http request for the k8s API.

View File

@@ -13,8 +13,8 @@ import (
"regexp"
"strings"
"github.com/micro/go-micro/v2/logger"
"github.com/micro/go-micro/v2/util/kubernetes/api"
"github.com/micro/go-micro/v3/logger"
"github.com/micro/go-micro/v3/util/kubernetes/api"
)
var (

View File

@@ -7,7 +7,7 @@ import (
"errors"
"net/http"
"github.com/micro/go-micro/v2/util/kubernetes/api"
"github.com/micro/go-micro/v3/util/kubernetes/api"
)
const (

View File

@@ -1,6 +1,6 @@
# Log
DEPRECATED: use github.com/micro/go-micro/v2/logger interface
DEPRECATED: use github.com/micro/go-micro/v3/logger interface
This is the global logger for all micro based libraries.

View File

@@ -1,5 +1,5 @@
// Package log is a global internal logger
// DEPRECATED: this is frozen package, use github.com/micro/go-micro/v2/logger
// DEPRECATED: this is frozen package, use github.com/micro/go-micro/v3/logger
package log
import (
@@ -7,8 +7,8 @@ import (
"os"
"sync/atomic"
dlog "github.com/micro/go-micro/v2/debug/log"
nlog "github.com/micro/go-micro/v2/logger"
dlog "github.com/micro/go-micro/v3/debug/log"
nlog "github.com/micro/go-micro/v3/logger"
)
// level is a log level

View File

@@ -8,7 +8,7 @@ import (
"sync/atomic"
"time"
log "github.com/micro/go-micro/v2/logger"
log "github.com/micro/go-micro/v3/logger"
"github.com/miekg/dns"
"golang.org/x/net/ipv4"
"golang.org/x/net/ipv6"

View File

@@ -5,10 +5,11 @@ import (
"context"
"sync"
"github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/debug/service/handler"
"github.com/micro/go-micro/v2/proxy"
"github.com/micro/go-micro/v2/server"
"github.com/micro/go-micro/v3/client/grpc"
"github.com/micro/go-micro/v3/debug/service/handler"
"github.com/micro/go-micro/v3/proxy"
"github.com/micro/go-micro/v3/server"
"github.com/micro/go-micro/v3/server/mucp"
)
// Server is a proxy muxer that incudes the use of the DefaultHandler
@@ -17,6 +18,14 @@ type Server struct {
Name string
// Proxy handler
Proxy proxy.Proxy
// The default handler
Handler Handler
}
type Handler interface {
proxy.Proxy
NewHandler(interface{}, ...server.HandlerOption) server.Handler
Handle(server.Handler) error
}
var (
@@ -25,32 +34,35 @@ var (
func (s *Server) ProcessMessage(ctx context.Context, msg server.Message) error {
if msg.Topic() == s.Name {
return server.DefaultRouter.ProcessMessage(ctx, msg)
return s.Handler.ProcessMessage(ctx, msg)
}
return s.Proxy.ProcessMessage(ctx, msg)
}
func (s *Server) ServeRequest(ctx context.Context, req server.Request, rsp server.Response) error {
if req.Service() == s.Name {
return server.DefaultRouter.ServeRequest(ctx, req, rsp)
return s.Handler.ServeRequest(ctx, req, rsp)
}
return s.Proxy.ServeRequest(ctx, req, rsp)
}
func New(name string, p proxy.Proxy) *Server {
r := mucp.DefaultRouter
// only register this once
once.Do(func() {
server.DefaultRouter.Handle(
r.Handle(
// inject the debug handler
server.DefaultRouter.NewHandler(
handler.NewHandler(client.DefaultClient),
r.NewHandler(
handler.NewHandler(grpc.NewClient()),
server.InternalHandler(true),
),
)
})
return &Server{
Name: name,
Proxy: p,
Name: name,
Proxy: p,
Handler: r,
}
}

View File

@@ -5,7 +5,7 @@ import (
"time"
"github.com/google/uuid"
"github.com/micro/go-micro/v2/transport"
"github.com/micro/go-micro/v3/transport"
)
type pool struct {

View File

@@ -4,8 +4,8 @@ import (
"testing"
"time"
"github.com/micro/go-micro/v2/transport"
"github.com/micro/go-micro/v2/transport/memory"
"github.com/micro/go-micro/v3/transport"
"github.com/micro/go-micro/v3/transport/memory"
)
func testPool(t *testing.T, size int, ttl time.Duration) {

View File

@@ -3,7 +3,7 @@ package pool
import (
"time"
"github.com/micro/go-micro/v2/transport"
"github.com/micro/go-micro/v3/transport"
)
type Options struct {

View File

@@ -4,7 +4,7 @@ package pool
import (
"time"
"github.com/micro/go-micro/v2/transport"
"github.com/micro/go-micro/v3/transport"
)
// Pool is an interface for connection pooling

View File

@@ -1,33 +0,0 @@
// Package proto contains utility functions for working with protobufs
package proto
import (
"github.com/micro/go-micro/v2/router"
pbRtr "github.com/micro/go-micro/v2/router/service/proto"
)
// RouteToProto encodes route into protobuf and returns it
func RouteToProto(route router.Route) *pbRtr.Route {
return &pbRtr.Route{
Service: route.Service,
Address: route.Address,
Gateway: route.Gateway,
Network: route.Network,
Router: route.Router,
Link: route.Link,
Metric: int64(route.Metric),
}
}
// ProtoToRoute decodes protobuf route into router route and returns it
func ProtoToRoute(route *pbRtr.Route) router.Route {
return router.Route{
Service: route.Service,
Address: route.Address,
Gateway: route.Gateway,
Network: route.Network,
Router: route.Router,
Link: route.Link,
Metric: route.Metric,
}
}

View File

@@ -1,7 +1,7 @@
package registry
import (
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v3/registry"
)
func addNodes(old, neu []*registry.Node) []*registry.Node {

View File

@@ -4,7 +4,7 @@ import (
"os"
"testing"
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v3/registry"
)
func TestRemove(t *testing.T) {

View File

@@ -3,7 +3,7 @@ package scope
import (
"fmt"
"github.com/micro/go-micro/v2/store"
"github.com/micro/go-micro/v3/store"
)
// Scope extends the store, applying a prefix to each request

View File

@@ -4,7 +4,7 @@ package socket
import (
"io"
"github.com/micro/go-micro/v2/transport"
"github.com/micro/go-micro/v3/transport"
)
// Socket is our pseudo socket for transport.Socket

View File

@@ -5,10 +5,11 @@ import (
"context"
"sync"
"github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/codec"
"github.com/micro/go-micro/v2/metadata"
"github.com/micro/go-micro/v2/server"
"github.com/micro/go-micro/v3/client"
"github.com/micro/go-micro/v3/client/mucp"
"github.com/micro/go-micro/v3/codec"
"github.com/micro/go-micro/v3/metadata"
"github.com/micro/go-micro/v3/server"
)
type Stream interface {
@@ -81,7 +82,7 @@ func New(service, endpoint string, req interface{}, s Stream) server.Stream {
Stream: s,
request: &request{
context: s.Context(),
Request: client.DefaultClient.NewRequest(service, endpoint, req),
Request: mucp.NewClient().NewRequest(service, endpoint, req),
},
}
}

View File

@@ -3,7 +3,7 @@ package sync
import (
"time"
"github.com/micro/go-micro/v2/store"
"github.com/micro/go-micro/v3/store"
"github.com/pkg/errors"
)

View File

@@ -3,7 +3,7 @@ package sync
import (
"time"
"github.com/micro/go-micro/v2/store"
"github.com/micro/go-micro/v3/store"
)
// Options represents Sync options

View File

@@ -7,7 +7,7 @@ import (
"time"
"github.com/ef-ds/deque"
"github.com/micro/go-micro/v2/store"
"github.com/micro/go-micro/v3/store"
"github.com/pkg/errors"
)

View File

@@ -1,7 +1,7 @@
package test
import (
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v3/registry"
)
var (

View File

@@ -6,9 +6,9 @@ import (
"time"
"github.com/google/uuid"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/store"
"github.com/micro/go-micro/v2/util/token"
"github.com/micro/go-micro/v3/auth"
"github.com/micro/go-micro/v3/store"
"github.com/micro/go-micro/v3/util/token"
)
// Basic implementation of token provider, backed by the store

View File

@@ -3,9 +3,9 @@ package basic
import (
"testing"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/store/memory"
"github.com/micro/go-micro/v2/util/token"
"github.com/micro/go-micro/v3/auth"
"github.com/micro/go-micro/v3/store/memory"
"github.com/micro/go-micro/v3/util/token"
)
func TestGenerate(t *testing.T) {

View File

@@ -5,8 +5,8 @@ import (
"time"
"github.com/dgrijalva/jwt-go"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/util/token"
"github.com/micro/go-micro/v3/auth"
"github.com/micro/go-micro/v3/util/token"
)
// authClaims to be encoded in the JWT

View File

@@ -5,8 +5,8 @@ import (
"testing"
"time"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/util/token"
"github.com/micro/go-micro/v3/auth"
"github.com/micro/go-micro/v3/util/token"
)
func TestGenerate(t *testing.T) {

View File

@@ -3,7 +3,7 @@ package token
import (
"time"
"github.com/micro/go-micro/v2/store"
"github.com/micro/go-micro/v3/store"
)
type Options struct {

View File

@@ -4,7 +4,7 @@ import (
"errors"
"time"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v3/auth"
)
var (

View File

@@ -5,13 +5,13 @@ import (
"reflect"
"strings"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/debug/stats"
"github.com/micro/go-micro/v2/debug/trace"
"github.com/micro/go-micro/v2/errors"
"github.com/micro/go-micro/v2/metadata"
"github.com/micro/go-micro/v2/server"
"github.com/micro/go-micro/v3/auth"
"github.com/micro/go-micro/v3/client"
"github.com/micro/go-micro/v3/debug/stats"
"github.com/micro/go-micro/v3/debug/trace"
"github.com/micro/go-micro/v3/errors"
"github.com/micro/go-micro/v3/metadata"
"github.com/micro/go-micro/v3/server"
)
type fromServiceWrapper struct {
@@ -313,7 +313,7 @@ func (c *cacheWrapper) Call(ctx context.Context, req client.Request, rsp interfa
}
// check to see if there is a response cached, if there is assign it
if r, ok := cache.Get(ctx, &req); ok {
if r, ok := cache.Get(ctx, req); ok {
val := reflect.ValueOf(rsp).Elem()
val.Set(reflect.ValueOf(r).Elem())
return nil
@@ -325,7 +325,7 @@ func (c *cacheWrapper) Call(ctx context.Context, req client.Request, rsp interfa
}
// set the result in the cache
cache.Set(ctx, &req, rsp, options.CacheExpiry)
cache.Set(ctx, req, rsp, options.CacheExpiry)
return nil
}

View File

@@ -4,14 +4,17 @@ import (
"context"
"testing"
"github.com/micro/go-micro/v2/broker"
bmemory "github.com/micro/go-micro/v2/broker/memory"
"github.com/micro/go-micro/v2/client"
rmemory "github.com/micro/go-micro/v2/registry/memory"
"github.com/micro/go-micro/v2/router"
"github.com/micro/go-micro/v2/server"
tmemory "github.com/micro/go-micro/v2/transport/memory"
wrapper "github.com/micro/go-micro/v2/util/wrapper"
"github.com/micro/go-micro/v3/broker"
bmemory "github.com/micro/go-micro/v3/broker/memory"
"github.com/micro/go-micro/v3/client"
"github.com/micro/go-micro/v3/client/grpc"
rmemory "github.com/micro/go-micro/v3/registry/memory"
"github.com/micro/go-micro/v3/router"
rtreg "github.com/micro/go-micro/v3/router/registry"
"github.com/micro/go-micro/v3/server"
grpcsrv "github.com/micro/go-micro/v3/server/grpc"
tmemory "github.com/micro/go-micro/v3/transport/memory"
wrapper "github.com/micro/go-micro/v3/util/wrapper"
)
type TestFoo struct {
@@ -31,15 +34,20 @@ func (h *TestFoo) Bar(ctx context.Context, req *TestReq, rsp *TestRsp) error {
func TestStaticClientWrapper(t *testing.T) {
var err error
req := client.NewRequest("go.micro.service.foo", "TestFoo.Bar", &TestReq{}, client.WithContentType("application/json"))
req := grpc.NewClient().NewRequest(
"go.micro.service.foo",
"TestFoo.Bar",
&TestReq{},
client.WithContentType("application/json"),
)
rsp := &TestRsp{}
reg := rmemory.NewRegistry()
brk := bmemory.NewBroker(broker.Registry(reg))
tr := tmemory.NewTransport()
rtr := router.NewRouter(router.Registry(reg))
rtr := rtreg.NewRouter(router.Registry(reg))
srv := server.NewServer(
srv := grpcsrv.NewServer(
server.Broker(brk),
server.Registry(reg),
server.Name("go.micro.service.foo"),
@@ -54,7 +62,7 @@ func TestStaticClientWrapper(t *testing.T) {
t.Fatal(err)
}
cli := client.NewClient(
cli := grpc.NewClient(
client.Router(rtr),
client.Broker(brk),
client.Transport(tr),

View File

@@ -7,11 +7,12 @@ import (
"testing"
"time"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/errors"
"github.com/micro/go-micro/v2/metadata"
"github.com/micro/go-micro/v2/server"
"github.com/micro/go-micro/v3/auth"
"github.com/micro/go-micro/v3/client"
"github.com/micro/go-micro/v3/client/grpc"
"github.com/micro/go-micro/v3/errors"
"github.com/micro/go-micro/v3/metadata"
"github.com/micro/go-micro/v3/server"
)
func TestWrapper(t *testing.T) {
@@ -371,7 +372,7 @@ type testRsp struct {
}
func TestCacheWrapper(t *testing.T) {
req := client.NewRequest("go.micro.service.foo", "Foo.Bar", nil)
req := grpc.NewClient().NewRequest("go.micro.service.foo", "Foo.Bar", nil)
t.Run("NilCache", func(t *testing.T) {
cli := new(testClient)