From a361161a54fb43f6e6afe7b31fc4629ab24c09a0 Mon Sep 17 00:00:00 2001 From: smx_Moragn <1048492656@qq.com> Date: Sat, 19 Oct 2024 16:09:46 +0800 Subject: [PATCH] softly connect to cwgo-pkg --- go.mod | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- utils.go | 33 ------------------------------- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/go.mod b/go.mod index 4e8b448..8689c3d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/kitex-contrib/registry-consul -go 1.16 +go 1.21 require ( github.com/apache/thrift v0.20.0 @@ -10,6 +10,63 @@ require ( github.com/stretchr/testify v1.9.0 ) +require ( + github.com/armon/go-metrics v0.4.1 // indirect + github.com/bytedance/gopkg v0.1.1 // indirect + github.com/bytedance/sonic v1.12.2 // indirect + github.com/bytedance/sonic/loader v0.2.0 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/configmanager v0.2.2 // indirect + github.com/cloudwego/dynamicgo v0.4.0 // indirect + github.com/cloudwego/fastpb v0.0.5 // indirect + github.com/cloudwego/frugal v0.2.0 // indirect + github.com/cloudwego/gopkg v0.1.1 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/cloudwego/localsession v0.0.2 // indirect + github.com/cloudwego/netpoll v0.6.4 // indirect + github.com/cloudwego/runtimex v0.1.0 // indirect + github.com/cloudwego/thriftgo v0.3.17 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/fatih/color v1.16.0 // indirect + github.com/fatih/structtag v1.2.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-hclog v1.5.0 // indirect + github.com/hashicorp/go-immutable-radix v1.3.1 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/go-rootcerts v1.0.2 // indirect + github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/hashicorp/serf v0.10.1 // indirect + github.com/iancoleman/strcase v0.2.0 // indirect + github.com/jhump/protoreflect v1.8.2 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.4 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5 // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/tidwall/gjson v1.17.3 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + golang.org/x/arch v0.2.0 // indirect + golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect + golang.org/x/net v0.24.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect + google.golang.org/protobuf v1.33.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + replace github.com/apache/thrift => github.com/apache/thrift v0.13.0 replace github.com/cloudwego-contrib/cwgo-pkg/registry/consul => github.com/smx-Morgan/cwgo-pkg/registry/consul v0.0.0-20241016000926-d56ef7e0f578 diff --git a/utils.go b/utils.go index 5433d9a..a6b5f1d 100644 --- a/utils.go +++ b/utils.go @@ -18,10 +18,7 @@ package consul import ( "errors" - "fmt" "net" - - "github.com/cloudwego/kitex/pkg/registry" ) func getLocalIPv4Address() (string, error) { @@ -41,33 +38,3 @@ func getLocalIPv4Address() (string, error) { } return "", errors.New("not found ipv4 address") } - -func parseAddr(addr net.Addr) (host string, port int, err error) { - host, portStr, err := net.SplitHostPort(addr.String()) - if err != nil { - return "", 0, err - } - if host == "" || host == "::" { - host, err = getLocalIPv4Address() - if err != nil { - return "", 0, fmt.Errorf("get local ipv4 error, cause %w", err) - } - } - port, err = net.LookupPort(defaultNetwork, portStr) - if err != nil { - return "", 0, err - } - if port == 0 { - return "", 0, fmt.Errorf("invalid port %s", portStr) - } - - return host, port, nil -} - -func getServiceId(info *registry.Info) (string, error) { - host, port, err := parseAddr(info.Addr) - if err != nil { - return "", err - } - return fmt.Sprintf("%s:%s:%d", info.ServiceName, host, port), nil -}