fixup handler tests
This commit is contained in:
@@ -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{}
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user