From 5c917750c9a3eecb4032b811c162383e249525de Mon Sep 17 00:00:00 2001 From: fangyincheng <fangyincheng@sina.com> Date: Wed, 22 May 2019 10:21:54 +0800 Subject: [PATCH] Mod:del goext & format code --- .travis.yml | 1 - cluster/cluster_impl/base_cluster_invoker.go | 6 +- .../cluster_impl/failover_cluster_invoker.go | 4 +- cluster/loadbalance/random_test.go | 8 +- common/utils/net.go | 81 +++++++++++++++++++ common/utils/net_test.go | 15 ++++ config/config_loader.go | 5 +- examples/dubbo/go-client/app/client.go | 29 ++++--- examples/dubbo/go-client/app/version.go | 14 ---- examples/dubbo/go-server/app/server.go | 8 +- examples/dubbo/go-server/app/user.go | 9 ++- examples/dubbo/go-server/app/version.go | 14 ---- examples/jsonrpc/go-client/app/client.go | 31 +++---- examples/jsonrpc/go-client/app/user.go | 4 +- examples/jsonrpc/go-client/app/version.go | 14 ---- examples/jsonrpc/go-server/app/server.go | 8 +- examples/jsonrpc/go-server/app/user.go | 76 ++--------------- examples/jsonrpc/go-server/app/version.go | 14 ---- go.mod | 1 - protocol/dubbo/client.go | 4 +- registry/zookeeper/registry.go | 4 +- 21 files changed, 170 insertions(+), 180 deletions(-) create mode 100644 common/utils/net.go create mode 100644 common/utils/net_test.go diff --git a/.travis.yml b/.travis.yml index 2038d8ecc..4ecf2a1b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: go go: - "1.11" - - "1.12" env: - GO111MODULE=on diff --git a/cluster/cluster_impl/base_cluster_invoker.go b/cluster/cluster_impl/base_cluster_invoker.go index a270bef45..38c210bbb 100644 --- a/cluster/cluster_impl/base_cluster_invoker.go +++ b/cluster/cluster_impl/base_cluster_invoker.go @@ -15,7 +15,6 @@ package cluster_impl import ( - "github.com/AlexStocks/goext/net" "github.com/pkg/errors" "go.uber.org/atomic" ) @@ -23,6 +22,7 @@ import ( import ( "github.com/dubbo/go-for-apache-dubbo/cluster" "github.com/dubbo/go-for-apache-dubbo/common" + "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/version" ) @@ -59,7 +59,7 @@ func (invoker *baseClusterInvoker) IsAvailable() bool { //check invokers availables func (invoker *baseClusterInvoker) checkInvokers(invokers []protocol.Invoker, invocation protocol.Invocation) error { if len(invokers) == 0 { - ip, _ := gxnet.GetLocalIP() + ip, _ := utils.GetLocalIP() return errors.Errorf("Failed to invoke the method %v. No provider available for the service %v from "+ "registry %v on the consumer %v using the dubbo version %v .Please check if the providers have been started and registered.", invocation.MethodName(), invoker.directory.GetUrl().SubURL.Key(), invoker.directory.GetUrl().String(), ip, version.Version) @@ -71,7 +71,7 @@ func (invoker *baseClusterInvoker) checkInvokers(invokers []protocol.Invoker, in //check cluster invoker is destroyed or not func (invoker *baseClusterInvoker) checkWhetherDestroyed() error { if invoker.destroyed.Load() { - ip, _ := gxnet.GetLocalIP() + ip, _ := utils.GetLocalIP() return errors.Errorf("Rpc cluster invoker for %v on consumer %v use dubbo version %v is now destroyed! can not invoke any more. ", invoker.directory.GetUrl().Service(), ip, version.Version) } diff --git a/cluster/cluster_impl/failover_cluster_invoker.go b/cluster/cluster_impl/failover_cluster_invoker.go index a67081701..8642b63b3 100644 --- a/cluster/cluster_impl/failover_cluster_invoker.go +++ b/cluster/cluster_impl/failover_cluster_invoker.go @@ -15,7 +15,6 @@ package cluster_impl import ( - "github.com/AlexStocks/goext/net" "github.com/pkg/errors" ) @@ -23,6 +22,7 @@ import ( "github.com/dubbo/go-for-apache-dubbo/cluster" "github.com/dubbo/go-for-apache-dubbo/common/constant" "github.com/dubbo/go-for-apache-dubbo/common/extension" + "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/version" ) @@ -92,7 +92,7 @@ func (invoker *failoverClusterInvoker) Invoke(invocation protocol.Invocation) pr return result } } - ip, _ := gxnet.GetLocalIP() + ip, _ := utils.GetLocalIP() return &protocol.RPCResult{Err: errors.Errorf("Failed to invoke the method %v in the service %v . Tried %v times of "+ "the providers %v (%v/%v)from the registry %v on the consumer %v using the dubbo version %v. Last error is %v.", methodName, invoker.GetUrl().Service(), retries, providers, len(providers), len(invokers), invoker.directory.GetUrl(), ip, version.Version, result.Error().Error(), diff --git a/cluster/loadbalance/random_test.go b/cluster/loadbalance/random_test.go index 92244a1ce..5b94f6b27 100644 --- a/cluster/loadbalance/random_test.go +++ b/cluster/loadbalance/random_test.go @@ -38,7 +38,13 @@ func Test_RandomlbSelect(t *testing.T) { randomlb := NewRandomLoadBalance() invokers := []protocol.Invoker{} - for i := 0; i < 10; i++ { + + url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", 0)) + invokers = append(invokers, protocol.NewBaseInvoker(url)) + i := randomlb.Select(invokers, &invocation.RPCInvocation{}) + assert.True(t, i.GetUrl().URLEqual(url)) + + for i := 1; i < 10; i++ { url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i)) invokers = append(invokers, protocol.NewBaseInvoker(url)) } diff --git a/common/utils/net.go b/common/utils/net.go new file mode 100644 index 000000000..b157c223a --- /dev/null +++ b/common/utils/net.go @@ -0,0 +1,81 @@ +// Copyright 2016-2019 Alex Stocks +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package utils + +import ( + "net" +) + +import ( + "github.com/pkg/errors" +) + +var ( + privateBlocks []*net.IPNet +) + +func init() { + for _, b := range []string{"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"} { + if _, block, err := net.ParseCIDR(b); err == nil { + privateBlocks = append(privateBlocks, block) + } + } +} + +// ref: https://stackoverflow.com/questions/23558425/how-do-i-get-the-local-ip-address-in-go +func GetLocalIP() (string, error) { + ifs, err := net.Interfaces() + if err != nil { + return "", errors.WithStack(err) + } + + var ipAddr []byte + for _, i := range ifs { + addrs, err := i.Addrs() + if err != nil { + return "", errors.WithStack(err) + } + var ip net.IP + for _, addr := range addrs { + switch v := addr.(type) { + case *net.IPNet: + ip = v.IP + case *net.IPAddr: + ip = v.IP + } + + if !ip.IsLoopback() && ip.To4() != nil && isPrivateIP(ip.String()) { + ipAddr = ip + break + } + } + } + + if ipAddr == nil { + return "", errors.Errorf("can not get local IP") + } + + return net.IP(ipAddr).String(), nil +} + +func isPrivateIP(ipAddr string) bool { + ip := net.ParseIP(ipAddr) + for _, priv := range privateBlocks { + if priv.Contains(ip) { + return true + } + } + return false +} diff --git a/common/utils/net_test.go b/common/utils/net_test.go new file mode 100644 index 000000000..5230d8d9c --- /dev/null +++ b/common/utils/net_test.go @@ -0,0 +1,15 @@ +package utils + +import ( + "testing" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestGetLocalIP(t *testing.T) { + ip, err := GetLocalIP() + assert.NoError(t, err) + t.Log(ip) +} diff --git a/config/config_loader.go b/config/config_loader.go index 537f51727..511ccfbba 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -24,7 +24,6 @@ import ( ) import ( - "github.com/AlexStocks/goext/log" log "github.com/AlexStocks/log4go" "github.com/pkg/errors" "gopkg.in/yaml.v2" @@ -111,7 +110,7 @@ func consumerInit(confConFile string) error { return errors.WithMessagef(err, "time.ParseDuration(Connect_Timeout{%#v})", consumerConfig.Connect_Timeout) } - gxlog.CInfo("consumer config{%#v}\n", consumerConfig) + log.Debug("consumer config{%#v}\n", consumerConfig) return nil } @@ -134,7 +133,7 @@ func providerInit(confProFile string) error { return errors.Errorf("yaml.Unmarshal() = error:%v", errors.Cause(err)) } - gxlog.CInfo("provider config{%#v}\n", providerConfig) + log.Debug("provider config{%#v}\n", providerConfig) return nil } diff --git a/examples/dubbo/go-client/app/client.go b/examples/dubbo/go-client/app/client.go index 265245117..9e1ff392b 100644 --- a/examples/dubbo/go-client/app/client.go +++ b/examples/dubbo/go-client/app/client.go @@ -27,13 +27,12 @@ import ( ) import ( - "github.com/AlexStocks/goext/log" - "github.com/AlexStocks/goext/net" log "github.com/AlexStocks/log4go" "github.com/dubbogo/hessian2" ) import ( + "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/config" _ "github.com/dubbo/go-for-apache-dubbo/protocol/dubbo" _ "github.com/dubbo/go-for-apache-dubbo/registry/protocol" @@ -65,40 +64,40 @@ func main() { initProfiling() - gxlog.CInfo("\n\n\necho") + println("\n\n\necho") res, err := conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).Echo(context.TODO(), "OK") if err != nil { panic(err) } - gxlog.CInfo("res: %s", res) + println("res: %s\n", res) time.Sleep(3e9) - gxlog.CInfo("\n\n\nstart to test dubbo") + println("\n\n\nstart to test dubbo") user := &User{} err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser(context.TODO(), []interface{}{"A003"}, user) if err != nil { panic(err) } - gxlog.CInfo("response result: %v", user) + println("response result: %v", user) - gxlog.CInfo("\n\n\nstart to test dubbo - GetUser0") + println("\n\n\nstart to test dubbo - GetUser0") ret, err := conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser0(context.TODO(), "A003") if err != nil { panic(err) } - gxlog.CInfo("response result: %v", ret) + println("response result: %v", ret) - gxlog.CInfo("\n\n\nstart to test dubbo - getUser") + println("\n\n\nstart to test dubbo - getUser") user = &User{} err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser2(context.TODO(), []interface{}{1}, user) if err != nil { - fmt.Println("getUser - error: ", err) + println("getUser - error: %v", err) } else { - gxlog.CInfo("response result: %v", user) + println("response result: %v", user) } - gxlog.CInfo("\n\n\nstart to test dubbo illegal method") + println("\n\n\nstart to test dubbo illegal method") err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser1(context.TODO(), []interface{}{"A003"}, user) if err != nil { panic(err) @@ -120,7 +119,7 @@ func initProfiling() { addr string ) - ip, err = gxnet.GetLocalIP() + ip, err = utils.GetLocalIP() if err != nil { panic("cat not get local ip!") } @@ -155,3 +154,7 @@ func initSignal() { } } } + +func println(format string, args ...interface{}) { + fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) +} diff --git a/examples/dubbo/go-client/app/version.go b/examples/dubbo/go-client/app/version.go index 0e6fb9d13..33bb9cd02 100644 --- a/examples/dubbo/go-client/app/version.go +++ b/examples/dubbo/go-client/app/version.go @@ -1,17 +1,3 @@ -// Copyright 2016-2019 Yincheng Fang, Alex Stocks -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package main var ( diff --git a/examples/dubbo/go-server/app/server.go b/examples/dubbo/go-server/app/server.go index 287068f10..02f54ca04 100644 --- a/examples/dubbo/go-server/app/server.go +++ b/examples/dubbo/go-server/app/server.go @@ -22,16 +22,16 @@ import ( "os/signal" "strconv" "syscall" + "time" ) import ( - "github.com/AlexStocks/goext/net" - "github.com/AlexStocks/goext/time" log "github.com/AlexStocks/log4go" "github.com/dubbogo/hessian2" ) import ( + "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/config" _ "github.com/dubbo/go-for-apache-dubbo/protocol/dubbo" _ "github.com/dubbo/go-for-apache-dubbo/registry/protocol" @@ -81,7 +81,7 @@ func initProfiling() { addr string ) - ip, err = gxnet.GetLocalIP() + ip, err = utils.GetLocalIP() if err != nil { panic("can not get local ip!") } @@ -104,7 +104,7 @@ func initSignal() { case syscall.SIGHUP: // reload() default: - go gxtime.Future(survivalTimeout, func() { + go time.AfterFunc(time.Duration(float64(survivalTimeout)*float64(time.Second)), func() { log.Warn("app exit now by force...") os.Exit(1) }) diff --git a/examples/dubbo/go-server/app/user.go b/examples/dubbo/go-server/app/user.go index 30bb4bfa3..40b867b70 100644 --- a/examples/dubbo/go-server/app/user.go +++ b/examples/dubbo/go-server/app/user.go @@ -22,7 +22,6 @@ import ( ) import ( - "github.com/AlexStocks/goext/log" "github.com/dubbo/go-for-apache-dubbo/config" "github.com/dubbogo/hessian2" ) @@ -130,11 +129,11 @@ func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User user *User ) - gxlog.CInfo("req:%#v", req) + println("req:%#v", req) user, err = u.getUser(req[0].(string)) if err == nil { *rsp = *user - gxlog.CInfo("rsp:%#v", rsp) + println("rsp:%#v", rsp) // s, _ := json.Marshal(rsp) // fmt.Println("hello0:", string(s)) @@ -151,3 +150,7 @@ func (u *UserProvider) Service() string { func (u *UserProvider) Version() string { return "" } + +func println(format string, args ...interface{}) { + fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) +} diff --git a/examples/dubbo/go-server/app/version.go b/examples/dubbo/go-server/app/version.go index 1ecda45af..c7552b26e 100644 --- a/examples/dubbo/go-server/app/version.go +++ b/examples/dubbo/go-server/app/version.go @@ -1,17 +1,3 @@ -// Copyright 2016-2019 Yincheng Fang, Alex Stocks -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package main var ( diff --git a/examples/jsonrpc/go-client/app/client.go b/examples/jsonrpc/go-client/app/client.go index 781b55a84..40bea987b 100644 --- a/examples/jsonrpc/go-client/app/client.go +++ b/examples/jsonrpc/go-client/app/client.go @@ -27,12 +27,11 @@ import ( ) import ( - "github.com/AlexStocks/goext/log" - "github.com/AlexStocks/goext/net" log "github.com/AlexStocks/log4go" ) import ( + "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/config" _ "github.com/dubbo/go-for-apache-dubbo/protocol/jsonrpc" _ "github.com/dubbo/go-for-apache-dubbo/registry/protocol" @@ -60,41 +59,41 @@ func main() { initProfiling() - gxlog.CInfo("\n\n\necho") + println("\n\n\necho") res, err := conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).Echo(context.TODO(), "OK") if err != nil { - fmt.Println("echo - error: ", err) + println("echo - error: %v", err) } else { - gxlog.CInfo("res: %s", res) + println("res: %s", res) } time.Sleep(3e9) - gxlog.CInfo("\n\n\nstart to test jsonrpc") + println("\n\n\nstart to test jsonrpc") user := &JsonRPCUser{} err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser(context.TODO(), []interface{}{"A003"}, user) if err != nil { panic(err) } - gxlog.CInfo("response result: %v", user) + println("response result: %v", user) - gxlog.CInfo("\n\n\nstart to test dubbo - GetUser0") + println("\n\n\nstart to test dubbo - GetUser0") ret, err := conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser0(context.TODO(), "A003") if err != nil { panic(err) } - gxlog.CInfo("response result: %v", ret) + println("response result: %v", ret) - gxlog.CInfo("\n\n\nstart to test jsonrpc - getUser") + println("\n\n\nstart to test jsonrpc - getUser") user = &JsonRPCUser{} err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser2(context.TODO(), []interface{}{1}, user) if err != nil { - fmt.Println("getUser - error: ", err) + println("getUser - error: %v", err) } else { - gxlog.CInfo("response result: %v", user) + println("response result: %v", user) } - gxlog.CInfo("\n\n\nstart to test jsonrpc illegal method") + println("\n\n\nstart to test jsonrpc illegal method") err = conMap["com.ikurento.user.UserProvider"].GetRPCService().(*UserProvider).GetUser1(context.TODO(), []interface{}{"A003"}, user) if err != nil { panic(err) @@ -116,7 +115,7 @@ func initProfiling() { addr string ) - ip, err = gxnet.GetLocalIP() + ip, err = utils.GetLocalIP() if err != nil { panic("cat not get local ip!") } @@ -151,3 +150,7 @@ func initSignal() { } } } + +func println(format string, args ...interface{}) { + fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) +} diff --git a/examples/jsonrpc/go-client/app/user.go b/examples/jsonrpc/go-client/app/user.go index 9d18dad7f..8d9f7fa5b 100644 --- a/examples/jsonrpc/go-client/app/user.go +++ b/examples/jsonrpc/go-client/app/user.go @@ -17,10 +17,10 @@ package main import ( "context" "fmt" + "time" ) import ( - "github.com/AlexStocks/goext/time" "github.com/dubbo/go-for-apache-dubbo/config" ) @@ -39,7 +39,7 @@ type JsonRPCUser struct { func (u JsonRPCUser) String() string { return fmt.Sprintf( "User{ID:%s, Name:%s, Age:%d, Time:%s, Sex:%s}", - u.ID, u.Name, u.Age, gxtime.YMDPrint(int(u.Time), 0), u.Sex, + u.ID, u.Name, u.Age, time.Unix(u.Time, 0).Format("2006-01-02 15:04:05.99999"), u.Sex, ) } diff --git a/examples/jsonrpc/go-client/app/version.go b/examples/jsonrpc/go-client/app/version.go index 0e6fb9d13..33bb9cd02 100644 --- a/examples/jsonrpc/go-client/app/version.go +++ b/examples/jsonrpc/go-client/app/version.go @@ -1,17 +1,3 @@ -// Copyright 2016-2019 Yincheng Fang, Alex Stocks -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package main var ( diff --git a/examples/jsonrpc/go-server/app/server.go b/examples/jsonrpc/go-server/app/server.go index 9eb2da198..f905d26ee 100644 --- a/examples/jsonrpc/go-server/app/server.go +++ b/examples/jsonrpc/go-server/app/server.go @@ -22,15 +22,15 @@ import ( "os/signal" "strconv" "syscall" + "time" ) import ( - "github.com/AlexStocks/goext/net" - "github.com/AlexStocks/goext/time" log "github.com/AlexStocks/log4go" ) import ( + "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/config" _ "github.com/dubbo/go-for-apache-dubbo/protocol/jsonrpc" _ "github.com/dubbo/go-for-apache-dubbo/registry/protocol" @@ -74,7 +74,7 @@ func initProfiling() { addr string ) - ip, err = gxnet.GetLocalIP() + ip, err = utils.GetLocalIP() if err != nil { panic("cat not get local ip!") } @@ -97,7 +97,7 @@ func initSignal() { case syscall.SIGHUP: // reload() default: - go gxtime.Future(survivalTimeout, func() { + go time.AfterFunc(time.Duration(float64(survivalTimeout)*float64(time.Second)), func() { log.Warn("app exit now by force...") os.Exit(1) }) diff --git a/examples/jsonrpc/go-server/app/user.go b/examples/jsonrpc/go-server/app/user.go index 7c9bfcafe..4f65f4282 100644 --- a/examples/jsonrpc/go-server/app/user.go +++ b/examples/jsonrpc/go-server/app/user.go @@ -21,8 +21,6 @@ import ( ) import ( - "github.com/AlexStocks/goext/log" - "github.com/AlexStocks/goext/time" "github.com/dubbo/go-for-apache-dubbo/config" ) @@ -56,10 +54,6 @@ type ( Sex string `json:"sex"` } - UserId struct { - Id string - } - UserProvider struct { user map[string]User } @@ -69,7 +63,7 @@ var ( DefaultUser = User{ Id: "0", Name: "Alex Stocks", Age: 31, // Birth: int(time.Date(1985, time.November, 10, 23, 0, 0, 0, time.UTC).Unix()), - Birth: gxtime.YMD(1985, 11, 24, 15, 15, 0), + Birth: int(time.Date(1985, 11, 24, 15, 15, 0, 0, time.Local).Unix()), sex: Gender(MAN), } @@ -89,17 +83,6 @@ func init() { } } -/* -// you can define your json unmarshal function here -func (u *UserId) UnmarshalJSON(value []byte) error { - u.Id = string(value) - u.Id = strings.TrimPrefix(u.Id, "\"") - u.Id = strings.TrimSuffix(u.Id, `"`) - - return nil -} -*/ - func (u *UserProvider) getUser(userId string) (*User, error) { if user, ok := userMap.user[userId]; ok { return &user, nil @@ -108,66 +91,17 @@ func (u *UserProvider) getUser(userId string) (*User, error) { return nil, fmt.Errorf("invalid user id:%s", userId) } -/* -// can not work -func (u *UserProvider) GetUser(ctx context.Context, req *UserId, rsp *User) error { - var ( - err error - user *User - ) - user, err = u.getUser(req.Id) - if err == nil { - *rsp = *user - gxlog.CInfo("rsp:%#v", rsp) - // s, _ := json.Marshal(rsp) - // fmt.Println(string(s)) - - // s, _ = json.Marshal(*rsp) - // fmt.Println(string(s)) - } - return err -} -*/ - -/* -// work -func (u *UserProvider) GetUser(ctx context.Context, req *string, rsp *User) error { - var ( - err error - user *User - ) - - gxlog.CInfo("req:%#v", *req) - user, err = u.getUser(*req) - if err == nil { - *rsp = *user - gxlog.CInfo("rsp:%#v", rsp) - // s, _ := json.Marshal(rsp) - // fmt.Println(string(s)) - - // s, _ = json.Marshal(*rsp) - // fmt.Println(string(s)) - } - return err -} -*/ - func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User) error { var ( err error user *User ) - gxlog.CInfo("req:%#v", req) + println("req:%#v", req) user, err = u.getUser(req[0].(string)) if err == nil { *rsp = *user - gxlog.CInfo("rsp:%#v", rsp) - // s, _ := json.Marshal(rsp) - // fmt.Println("hello0:", string(s)) - - // s, _ = json.Marshal(*rsp) - // fmt.Println("hello1:", string(s)) + println("rsp:%#v", rsp) } return err } @@ -179,3 +113,7 @@ func (u *UserProvider) Service() string { func (u *UserProvider) Version() string { return "" } + +func println(format string, args ...interface{}) { + fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) +} diff --git a/examples/jsonrpc/go-server/app/version.go b/examples/jsonrpc/go-server/app/version.go index 1ecda45af..c7552b26e 100644 --- a/examples/jsonrpc/go-server/app/version.go +++ b/examples/jsonrpc/go-server/app/version.go @@ -1,17 +1,3 @@ -// Copyright 2016-2019 Yincheng Fang, Alex Stocks -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package main var ( diff --git a/go.mod b/go.mod index d8c111da8..0c8978562 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,6 @@ module github.com/dubbo/go-for-apache-dubbo require ( github.com/AlexStocks/getty v0.0.0-20190513203438-4a52b6874223 - github.com/AlexStocks/goext v0.3.2 github.com/AlexStocks/log4go v1.0.2 github.com/dubbogo/hessian2 v0.0.0-20190521160428-dff5b932f479 github.com/pkg/errors v0.8.1 diff --git a/protocol/dubbo/client.go b/protocol/dubbo/client.go index 344cc67c7..8791882ab 100644 --- a/protocol/dubbo/client.go +++ b/protocol/dubbo/client.go @@ -22,10 +22,10 @@ import ( import ( "github.com/AlexStocks/getty" - "github.com/AlexStocks/goext/sync/atomic" log "github.com/AlexStocks/log4go" "github.com/dubbogo/hessian2" "github.com/pkg/errors" + "go.uber.org/atomic" "gopkg.in/yaml.v2" ) @@ -143,7 +143,7 @@ type AsyncCallback func(response CallResponse) type Client struct { conf ClientConfig pool *gettyRPCClientPool - sequence gxatomic.Uint64 + sequence atomic.Uint64 pendingLock sync.RWMutex pendingResponses map[SequenceType]*PendingResponse diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index f8f26705b..10173132b 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -26,7 +26,6 @@ import ( ) import ( - "github.com/AlexStocks/goext/net" log "github.com/AlexStocks/log4go" "github.com/pkg/errors" "github.com/samuel/go-zookeeper/zk" @@ -36,6 +35,7 @@ import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" "github.com/dubbo/go-for-apache-dubbo/common/extension" + "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/registry" "github.com/dubbo/go-for-apache-dubbo/version" ) @@ -53,7 +53,7 @@ var ( func init() { processID = fmt.Sprintf("%d", os.Getpid()) - localIP, _ = gxnet.GetLocalIP() + localIP, _ = utils.GetLocalIP() //plugins.PluggableRegistries["zookeeper"] = newZkRegistry extension.SetRegistry("zookeeper", newZkRegistry) } -- GitLab