diff --git a/client/client_transport.go b/client/client_transport.go index e3d31b60efb91c4d095782614f1d5705f5fc9d81..7f5b6f394a4981cf240f420206712ce6904ae8b5 100644 --- a/client/client_transport.go +++ b/client/client_transport.go @@ -1,31 +1,24 @@ package client -// -//type Transport interface { -// Call(ctx context.Context, url *service.ServiceURL, request Request, resp interface{}) error -// NewRequest(conf service.ServiceConfig, method string, args interface{}) Request -//} -// -//////////////////////////////////////////////// -//// Request -//////////////////////////////////////////////// -// -//type Request struct { -// ID int64 -// Group string -// Protocol string -// Version string -// Service string -// Method string -// Args interface{} -// ContentType string -//} -// -//func (r *Request) ServiceConfig() service.ServiceConfigIf { -// return &service.ServiceConfig{ -// Protocol: r.Protocol, -// Service: r.Service, -// Group: r.Group, -// Version: r.Version, -// } -//} + +import ( + "context" +) + +import ( + "github.com/dubbo/dubbo-go/registry" +) + +type Transport interface { + Call(ctx context.Context, url *registry.ServiceURL, request Request, resp interface{}) error + NewRequest(conf registry.ServiceConfig, method string, args interface{}) Request +} + +////////////////////////////////////////////// +// Request +////////////////////////////////////////////// + +type Request interface { + ServiceConfig() registry.DefaultServiceConfig +} + diff --git a/client/invoker/invoker.go b/client/invoker/invoker.go index a535f9363f90a36acc108ef5bcd24bcbe6c10f06..4bd6337e46379fff82474226f7a5e66f41c195c7 100644 --- a/client/invoker/invoker.go +++ b/client/invoker/invoker.go @@ -2,6 +2,7 @@ package invoker import ( "context" + "github.com/dubbo/dubbo-go/client" "sync" "time" ) @@ -174,14 +175,15 @@ func (ivk *Invoker) getService(registryConf registry.DefaultServiceConfig) (*Ser return newSvcArr, nil } -func (ivk *Invoker) HttpCall(ctx context.Context, reqId int64, registryConf registry.DefaultServiceConfig, req jsonrpc.Request, resp interface{}) error { +func (ivk *Invoker) HttpCall(ctx context.Context, reqId int64, req client.Request, resp interface{}) error { - registryArray, err := ivk.getService(registryConf) + serviceConf := req.ServiceConfig() + registryArray, err := ivk.getService(serviceConf) if err != nil { return err } if len(registryArray.arr) == 0 { - return jerrors.New("cannot find svc " + registryConf.String()) + return jerrors.New("cannot find svc " + serviceConf.String()) } url, err := ivk.selector.Select(reqId, registryArray) if err != nil { diff --git a/examples/jsonrpc/go-client/app/test.go b/examples/jsonrpc/go-client/app/test.go index 95a78f29adfa462fdc956a5a601a6bf3ec6277cd..ccd33ca2e9fd40cc0885c7076a77778d5ca52573 100644 --- a/examples/jsonrpc/go-client/app/test.go +++ b/examples/jsonrpc/go-client/app/test.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "github.com/dubbo/dubbo-go/client" "github.com/dubbo/dubbo-go/registry" _ "net/http/pprof" ) @@ -13,7 +14,6 @@ import ( import ( "github.com/dubbo/dubbo-go/examples" - "github.com/dubbo/dubbo-go/jsonrpc" "github.com/dubbo/dubbo-go/public" ) @@ -25,7 +25,7 @@ func testJsonrpc(clientConfig *examples.ClientConfig, userKey string, method str user *JsonRPCUser ctx context.Context conf registry.DefaultServiceConfig - req jsonrpc.Request + req client.Request ) serviceIdx = -1 @@ -59,7 +59,7 @@ func testJsonrpc(clientConfig *examples.ClientConfig, userKey string, method str user = new(JsonRPCUser) - err = clientInvoker.HttpCall(ctx, 1, conf, req, user) + err = clientInvoker.HttpCall(ctx, 1, req, user) if err != nil { panic(err) } else { diff --git a/jsonrpc/http.go b/jsonrpc/http.go index 131f3c1887f8b3444dd6e6a44807eb309f6bb6aa..daf1a71d3b7ccdea64743fc039df9d488e98d239 100644 --- a/jsonrpc/http.go +++ b/jsonrpc/http.go @@ -5,6 +5,7 @@ import ( "bytes" "context" "fmt" + "github.com/dubbo/dubbo-go/client" "io/ioutil" "net" "net/http" @@ -39,8 +40,8 @@ type Request struct { contentType string } -func (r *Request) ServiceConfig() registry.ServiceConfig { - return ®istry.DefaultServiceConfig{ +func (r *Request) ServiceConfig() registry.DefaultServiceConfig { + return registry.DefaultServiceConfig{ Protocol: r.protocol, Service: r.service, Group: r.group, @@ -86,8 +87,8 @@ func NewHTTPClient(opt *HTTPOptions) *HTTPClient { } } -func (c *HTTPClient) NewRequest(conf registry.DefaultServiceConfig, method string, args interface{}) Request { - return Request{ +func (c *HTTPClient) NewRequest(conf registry.DefaultServiceConfig, method string, args interface{}) client.Request { + return &Request{ ID: atomic.AddInt64(&c.ID, 1), group: conf.Group, protocol: conf.Protocol, @@ -98,8 +99,9 @@ func (c *HTTPClient) NewRequest(conf registry.DefaultServiceConfig, method strin } } -func (c *HTTPClient) Call(ctx context.Context, service *registry.ServiceURL, req Request, rsp interface{}) error { +func (c *HTTPClient) Call(ctx context.Context, service *registry.ServiceURL, request client.Request, rsp interface{}) error { // header + req := request.(*Request) httpHeader := http.Header{} httpHeader.Set("Content-Type", "application/json") httpHeader.Set("Accept", "application/json")