fixup handler tests

This commit is contained in:
Asim Aslam
2020-04-12 14:29:38 +01:00
parent d03a02f2e4
commit b08c636b44
5 changed files with 28 additions and 53 deletions

View File

@@ -65,7 +65,7 @@ func (a *apiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
// create request and response
c := a.opts.Service.Client()
c := a.opts.Client
req := c.NewRequest(service.Name, service.Endpoint.Name, request)
rsp := &api.Response{}

View File

@@ -118,7 +118,7 @@ func (e *event) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
// get client
c := e.opts.Service.Client()
c := e.opts.Client
// create publication
p := c.NewMessage(topic, ev)

View File

@@ -1,8 +1,9 @@
package handler
import (
"github.com/micro/go-micro/v2"
"github.com/micro/go-micro/v2/api/router"
"github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/client/grpc"
)
var (
@@ -13,7 +14,7 @@ type Options struct {
MaxRecvSize int64
Namespace string
Router router.Router
Service micro.Service
Client client.Client
}
type Option func(o *Options)
@@ -25,9 +26,8 @@ func NewOptions(opts ...Option) Options {
o(&options)
}
// create service if its blank
if options.Service == nil {
WithService(micro.NewService())(&options)
if options.Client == nil {
WithClient(grpc.NewClient())(&options)
}
// set namespace if blank
@@ -56,10 +56,9 @@ func WithRouter(r router.Router) Option {
}
}
// WithService specifies a micro.Service
func WithService(s micro.Service) Option {
func WithClient(c client.Client) Option {
return func(o *Options) {
o.Service = s
o.Client = c
}
}

View File

@@ -113,7 +113,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
// micro client
c := h.opts.Service.Client()
c := h.opts.Client
// create context
cx := ctx.FromRequest(r)