1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

fix errors

This commit is contained in:
Asim Aslam 2019-06-06 17:58:21 +01:00
parent a58bc8e75c
commit 2cc18d6edc
3 changed files with 10 additions and 10 deletions

View File

@ -10,14 +10,14 @@ import (
"github.com/micro/go-micro/client" "github.com/micro/go-micro/client"
"github.com/micro/go-micro/codec" "github.com/micro/go-micro/codec"
"github.com/micro/go-micro/codec/bytes" "github.com/micro/go-micro/codec/bytes"
"github.com/micro/go-micro/init" "github.com/micro/go-micro/options"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
"github.com/micro/go-micro/service/grpc" "github.com/micro/go-micro/service/grpc"
) )
// Proxy will transparently proxy requests to the backend. // Proxy will transparently proxy requests to the backend.
// If no backend is specified it will call a service using the client. // If no backend is specified it will call a service using the client.
// If the service matches the Name it will use the server.DefaultProxy. // If the service matches the Name it will use the server.DefaultRouter.
type Proxy struct { type Proxy struct {
// Name of the local service. In the event it's to be left alone // Name of the local service. In the event it's to be left alone
Name string Name string
@ -36,7 +36,7 @@ type Proxy struct {
Client client.Client Client client.Client
// The proxy options // The proxy options
Options init.Options Options options.Options
} }
var ( var (
@ -94,7 +94,7 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server
// check service route // check service route
if req.Service() == p.Name { if req.Service() == p.Name {
// use the default router // use the default router
return server.DefaultProxy.ServeRequest(ctx, req, rsp) return server.DefaultRouter.ServeRequest(ctx, req, rsp)
} }
opts := []client.CallOption{} opts := []client.CallOption{}
@ -170,9 +170,9 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server
} }
// NewProxy returns a new grpc proxy server // NewProxy returns a new grpc proxy server
func NewProxy(opts ...init.Option) *Proxy { func NewProxy(opts ...options.Option) *Proxy {
return &Proxy{ return &Proxy{
Options: init.NewOptions(opts...), Options: options.NewOptions(opts...),
} }
} }
@ -233,7 +233,7 @@ func NewService(opts ...micro.Option) micro.Service {
// prepend router to opts // prepend router to opts
opts = append([]micro.Option{ opts = append([]micro.Option{
micro.Name(name), micro.Name(name),
WithProxy(router), WithRouter(router),
}, opts...) }, opts...)
// create the new service // create the new service

View File

@ -13,12 +13,12 @@ func WithBackend(url string) micro.Option {
// not set // not set
if r == nil { if r == nil {
r = DefaultRouter r = DefaultProxy
o.Server.Init(server.WithRouter(r)) o.Server.Init(server.WithRouter(r))
} }
// check its a proxy router // check its a proxy router
if proxyRouter, ok := r.(*Router); ok { if proxyRouter, ok := r.(*Proxy); ok {
proxyRouter.Backend = url proxyRouter.Backend = url
} }
} }

View File

@ -12,7 +12,7 @@ import (
type Proxy interface { type Proxy interface {
options.Options options.Options
// ServeRequest will serve a request // ServeRequest will serve a request
ServeRequest(context.Context, Request, Response) error ServeRequest(context.Context, server.Request, server.Response) error
// run the proxy // run the proxy
Run() error Run() error
} }