diff --git a/client/http.go b/client/jsonrpc/http.go similarity index 97% rename from client/http.go rename to client/jsonrpc/http.go index 9dbb1366cf69cd6ecbc393583cf5e199d3a98f4e..eb871e06767c23873ddc1e6b883afac7dbb6d15f 100644 --- a/client/http.go +++ b/client/jsonrpc/http.go @@ -1,4 +1,4 @@ -package client +package jsonrpc import ( "bufio" @@ -20,13 +20,10 @@ import ( ) import ( + "github.com/dubbo/dubbo-go/public" "github.com/dubbo/dubbo-go/registry" ) -const ( - DUBBOGO_CTX_KEY = "dubbogo-ctx" -) - ////////////////////////////////////////////// // Request ////////////////////////////////////////////// @@ -120,7 +117,7 @@ func (c *HTTPClient) Call(ctx context.Context, service registry.ServiceURL, req reqTimeout = 1e8 } httpHeader.Set("Timeout", fmt.Sprintf("%d", reqTimeout)) - if md, ok := ctx.Value(DUBBOGO_CTX_KEY).(map[string]string); ok { + if md, ok := ctx.Value(public.DUBBOGO_CTX_KEY).(map[string]string); ok { for k := range md { httpHeader.Set(k, md[k]) } diff --git a/client/json.go b/client/jsonrpc/json.go old mode 100755 new mode 100644 similarity index 89% rename from client/json.go rename to client/jsonrpc/json.go index 8dccd960576251658195d66eca0e0f665bfa2046..4fa0b79839d496e5fc25f722197e9996c568309f --- a/client/json.go +++ b/client/jsonrpc/json.go @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -package client +package jsonrpc import ( "bytes" @@ -40,43 +40,6 @@ const ( VERSION = "2.0" ) -////////////////////////////////////////// -// codec type -////////////////////////////////////////// - -type CodecType int - -const ( - CODECTYPE_UNKNOWN CodecType = iota - CODECTYPE_JSONRPC -) - -var codecTypeStrings = [...]string{ - "unknown", - "jsonrpc", -} - -func (c CodecType) String() string { - typ := CODECTYPE_UNKNOWN - switch c { - case CODECTYPE_JSONRPC: - typ = c - } - - return codecTypeStrings[typ] -} - -func GetCodecType(t string) CodecType { - var typ = CODECTYPE_UNKNOWN - - switch t { - case codecTypeStrings[CODECTYPE_JSONRPC]: - typ = CODECTYPE_JSONRPC - } - - return typ -} - ////////////////////////////////////////// // json codec ////////////////////////////////////////// diff --git a/examples/client/app/client.go b/examples/client/app/client.go index ab1ff3d54889d6e3634ae7aca5b51eff68feeaec..d5870280d6878908cd83c121639c0263692e512c 100644 --- a/examples/client/app/client.go +++ b/examples/client/app/client.go @@ -19,7 +19,7 @@ import ( ) import ( - "github.com/dubbo/dubbo-go/client" + "github.com/dubbo/dubbo-go/public" "github.com/dubbo/dubbo-go/registry" ) @@ -54,7 +54,7 @@ func main() { func initClient() { var ( err error - codecType client.CodecType + codecType public.CodecType ) if clientConfig == nil { @@ -96,8 +96,8 @@ func initClient() { } for idx := range clientConfig.Service_List { - codecType = client.GetCodecType(clientConfig.Service_List[idx].Protocol) - if codecType == client.CODECTYPE_UNKNOWN { + codecType = public.GetCodecType(clientConfig.Service_List[idx].Protocol) + if codecType == public.CODECTYPE_UNKNOWN { panic(fmt.Sprintf("unknown protocol %s", clientConfig.Service_List[idx].Protocol)) } } diff --git a/examples/client/app/test.go b/examples/client/app/test.go index 9ec5ccbdc6f7b414972f715347c507b64bb9161a..a25f39ac8d4a8be99a544278b2a6484476ed80ec 100644 --- a/examples/client/app/test.go +++ b/examples/client/app/test.go @@ -13,7 +13,8 @@ import ( ) import ( - "github.com/dubbo/dubbo-go/client" + "github.com/dubbo/dubbo-go/client/jsonrpc" + "github.com/dubbo/dubbo-go/public" "github.com/dubbo/dubbo-go/registry" ) @@ -26,13 +27,13 @@ func testJsonrpc(userKey string) { user *JsonRPCUser ctx context.Context conf registry.ServiceConfig - req client.Request + req jsonrpc.Request serviceURL *registry.ServiceURL - clt *client.HTTPClient + clt *jsonrpc.HTTPClient ) - clt = client.NewHTTPClient( - &client.HTTPOptions{ + clt = jsonrpc.NewHTTPClient( + &jsonrpc.HTTPOptions{ HandshakeTimeout: clientConfig.connectTimeout, HTTPTimeout: clientConfig.requestTimeout, }, @@ -41,7 +42,7 @@ func testJsonrpc(userKey string) { serviceIdx = -1 service = "com.ikurento.user.UserProvider" for i := range clientConfig.Service_List { - if clientConfig.Service_List[i].Service == service && clientConfig.Service_List[i].Protocol == client.CODECTYPE_JSONRPC.String() { + if clientConfig.Service_List[i].Service == service && clientConfig.Service_List[i].Protocol == public.CODECTYPE_JSONRPC.String() { serviceIdx = i break } @@ -55,7 +56,7 @@ func testJsonrpc(userKey string) { // gxlog.CInfo("jsonrpc selected service %#v", clientConfig.Service_List[serviceIdx]) conf = registry.ServiceConfig{ Group: clientConfig.Service_List[serviceIdx].Group, - Protocol: client.CodecType(client.CODECTYPE_JSONRPC).String(), + Protocol: public.CodecType(public.CODECTYPE_JSONRPC).String(), Version: clientConfig.Service_List[serviceIdx].Version, Service: clientConfig.Service_List[serviceIdx].Service, } @@ -70,7 +71,7 @@ func testJsonrpc(userKey string) { } log.Debug("got serviceURL: %s", serviceURL) // Set arbitrary headers in context - ctx = context.WithValue(context.Background(), client.DUBBOGO_CTX_KEY, map[string]string{ + ctx = context.WithValue(context.Background(), public.DUBBOGO_CTX_KEY, map[string]string{ "X-Proxy-Id": "dubbogo", "X-Services": service, "X-Method": method, diff --git a/public/codec.go b/public/codec.go new file mode 100644 index 0000000000000000000000000000000000000000..89d64f8499e8f10fc6841cc65be6717085416acf --- /dev/null +++ b/public/codec.go @@ -0,0 +1,38 @@ +package public + +////////////////////////////////////////// +// codec type +////////////////////////////////////////// + +type CodecType int + +const ( + CODECTYPE_UNKNOWN CodecType = iota + CODECTYPE_JSONRPC +) + +var codecTypeStrings = [...]string{ + "unknown", + "jsonrpc", +} + +func (c CodecType) String() string { + typ := CODECTYPE_UNKNOWN + switch c { + case CODECTYPE_JSONRPC: + typ = c + } + + return codecTypeStrings[typ] +} + +func GetCodecType(t string) CodecType { + var typ = CODECTYPE_UNKNOWN + + switch t { + case codecTypeStrings[CODECTYPE_JSONRPC]: + typ = CODECTYPE_JSONRPC + } + + return typ +} diff --git a/public/const.go b/public/const.go new file mode 100644 index 0000000000000000000000000000000000000000..d7f385ecf4530ebc2174c7162a44a88e65106319 --- /dev/null +++ b/public/const.go @@ -0,0 +1,5 @@ +package public + +const ( + DUBBOGO_CTX_KEY = "dubbogo-ctx" +)