Skip to content
Snippets Groups Projects
Commit 157ee3ef authored by AlexStocks's avatar AlexStocks
Browse files

Mod: codectype and const

parent 74476c2e
No related branches found
No related tags found
No related merge requests found
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])
}
......
......@@ -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
//////////////////////////////////////////
......
......@@ -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))
}
}
......
......@@ -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,
......
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
}
package public
const (
DUBBOGO_CTX_KEY = "dubbogo-ctx"
)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment