diff --git a/Makefile b/Makefile index 46265203a92..85d4f529958 100644 --- a/Makefile +++ b/Makefile @@ -33,9 +33,8 @@ version: .PHONY: subup subup: @set -e; \ - cd examples; \ echo "Updating submodules..."; \ - git pull origin; \ + cd examples && git pull origin main; \ cd ..; # update and commit submodules diff --git a/contrib/registry/file/file_z_http_test.go b/contrib/registry/file/file_z_http_test.go index a1eac283b44..500837c3351 100644 --- a/contrib/registry/file/file_z_http_test.go +++ b/contrib/registry/file/file_z_http_test.go @@ -45,6 +45,7 @@ func Test_HTTP_Registry(t *testing.T) { gtest.C(t, func(t *gtest.T) { client := g.Client() + client.SetDiscovery(gsvc.GetRegistry()) client.SetPrefix(fmt.Sprintf("http://%s", svcName)) // GET t.Assert(client.GetContent(ctx, "/http-registry"), svcName) @@ -71,6 +72,7 @@ func Test_HTTP_Discovery_Disable(t *testing.T) { gtest.C(t, func(t *gtest.T) { client := g.Client() + client.SetDiscovery(gsvc.GetRegistry()) client.SetPrefix(fmt.Sprintf("http://%s", svcName)) result, err := client.Get(ctx, "/http-registry") defer result.Close() diff --git a/examples b/examples index a4a36715aa0..2544fee34dd 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit a4a36715aa01a720f136536c772028ddeaff213d +Subproject commit 2544fee34dd10e6914687f7335bd9e772215ce07 diff --git a/net/gclient/gclient.go b/net/gclient/gclient.go index f158808433b..10444a9fe5c 100644 --- a/net/gclient/gclient.go +++ b/net/gclient/gclient.go @@ -72,7 +72,7 @@ func New() *Client { header: make(map[string]string), cookies: make(map[string]string), builder: gsel.GetBuilder(), - discovery: gsvc.GetRegistry(), + discovery: nil, } c.header[httpHeaderUserAgent] = defaultClientAgent // It enables OpenTelemetry for client in default. diff --git a/net/gclient/gclient_discovery.go b/net/gclient/gclient_discovery.go index aa1a52f1aac..ff9a1df9d9f 100644 --- a/net/gclient/gclient_discovery.go +++ b/net/gclient/gclient_discovery.go @@ -16,7 +16,6 @@ import ( "github.com/gogf/gf/v2/internal/intlog" "github.com/gogf/gf/v2/net/gsel" "github.com/gogf/gf/v2/net/gsvc" - "github.com/gogf/gf/v2/text/gstr" ) type discoveryNode struct { @@ -39,7 +38,7 @@ var clientSelectorMap = gmap.New(true) // internalMiddlewareDiscovery is a client middleware that enables service discovery feature for client. func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response, err error) { - if c.discovery == nil && !isServiceName(r.URL.Host) { + if c.discovery == nil { return c.Next(r) } var ( @@ -107,11 +106,3 @@ func updateSelectorNodesByService(ctx context.Context, selector gsel.Selector, s } return selector.Update(ctx, nodes) } - -// isServiceName checks and returns whether given input parameter is service name or not. -// It checks by whether the parameter is address by containing port delimiter character ':'. -// -// It does not contain any port number if using service discovery. -func isServiceName(serviceNameOrAddress string) bool { - return !gstr.Contains(serviceNameOrAddress, gsvc.EndpointHostPortDelimiter) -} diff --git a/util/gconv/gconv_struct.go b/util/gconv/gconv_struct.go index 57fadd7c9d3..cbb6eb0b0cf 100644 --- a/util/gconv/gconv_struct.go +++ b/util/gconv/gconv_struct.go @@ -367,7 +367,7 @@ func bindVarToStructField( customConverterInput reflect.Value ok bool ) - if cachedFieldInfo.IsCustomConvert { + if cachedFieldInfo.HasCustomConvert { if customConverterInput, ok = srcValue.(reflect.Value); !ok { customConverterInput = reflect.ValueOf(srcValue) } diff --git a/util/gconv/internal/structcache/structcache_cached_field_info.go b/util/gconv/internal/structcache/structcache_cached_field_info.go index 1009295e28e..6b07cae15cc 100644 --- a/util/gconv/internal/structcache/structcache_cached_field_info.go +++ b/util/gconv/internal/structcache/structcache_cached_field_info.go @@ -50,8 +50,8 @@ type CachedFieldInfoBase struct { // Purpose: reduce the interface asserting cost in runtime. IsCommonInterface bool - // IsCustomConvert marks there custom converting function for this field type. - IsCustomConvert bool + // HasCustomConvert marks there custom converting function for this field type. + HasCustomConvert bool // StructField is the type info of this field. StructField reflect.StructField diff --git a/util/gconv/internal/structcache/structcache_cached_struct_info.go b/util/gconv/internal/structcache/structcache_cached_struct_info.go index 24510737684..bf6a10aad91 100644 --- a/util/gconv/internal/structcache/structcache_cached_struct_info.go +++ b/util/gconv/internal/structcache/structcache_cached_struct_info.go @@ -99,7 +99,7 @@ func (csi *CachedStructInfo) makeCachedFieldInfo( StructField: field, FieldIndexes: fieldIndexes, ConvertFunc: csi.genFieldConvertFunc(field.Type.String()), - IsCustomConvert: csi.checkTypeHasCustomConvert(field.Type), + HasCustomConvert: csi.checkTypeHasCustomConvert(field.Type), PriorityTagAndFieldName: csi.genPriorityTagAndFieldName(field, priorityTags), RemoveSymbolsFieldName: utils.RemoveSymbols(field.Name), }