Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(net/gclient): remove default discovery for gclient when Discovery feature enabled #4174

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions contrib/registry/file/file_z_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 71 files
+6 −1 .ai-prompt.zh.md
+2 −2 balancer/polaris/README.md
+2 −2 httpserver/jwt/README.ZH.MD
+3 −3 httpserver/proxy/README.ZH.MD
+2 −1 httpserver/rate-limit/README.ZH.MD
+7 −7 httpserver/response-json-array/README.ZH.MD
+1 −1 httpserver/upload-file/README.ZH.MD
+9 −6 httpserver/websocket/README.MD
+7 −5 httpserver/websocket/README.ZH.MD
+1 −1 nosql/mongodb/README.MD
+1 −1 nosql/mongodb/README.ZH.MD
+1 −1 nosql/redis/README.MD
+1 −1 nosql/redis/README.ZH.MD
+148 −0 practices/injection/README.MD
+149 −0 practices/injection/README.ZH.MD
+2 −2 practices/injection/app/gateway/Makefile
+12 −12 practices/injection/app/gateway/api/user/v1/user.go
+1 −1 practices/injection/app/gateway/internal/controller/user/user_new.go
+1 −1 practices/injection/app/gateway/internal/controller/user/user_v1_create.go
+1 −1 practices/injection/app/gateway/internal/controller/user/user_v1_delete.go
+1 −1 practices/injection/app/gateway/internal/controller/user/user_v1_get_list.go
+1 −1 practices/injection/app/gateway/internal/controller/user/user_v1_get_one.go
+1 −1 practices/injection/app/gateway/manifest/deploy/kustomize/base/configmap.yaml
+8 −8 practices/injection/app/gateway/manifest/deploy/kustomize/base/deployment.yaml
+2 −2 practices/injection/app/gateway/manifest/deploy/kustomize/base/service.yaml
+1 −1 practices/injection/app/gateway/manifest/deploy/kustomize/overlays/develop/configmap.yaml
+2 −2 practices/injection/app/gateway/manifest/deploy/kustomize/overlays/develop/deployment.yaml
+1 −1 practices/injection/app/gateway/manifest/deploy/kustomize/overlays/product/configmap.yaml
+2 −2 practices/injection/app/gateway/manifest/deploy/kustomize/overlays/product/deployment.yaml
+0 −61 practices/injection/app/user-service/internal/controller/user/user.go
+0 −10 practices/injection/app/user-service/internal/model/entity/user.go
+0 −72 practices/injection/app/user-service/internal/service/user/user.go
+0 −16 practices/injection/app/user-service/manifest/protobuf/entity/user.proto
+0 −47 practices/injection/app/user-service/manifest/protobuf/user/v1/user.proto
+2 −2 practices/injection/app/user/Makefile
+0 −0 practices/injection/app/user/README.MD
+4 −5 practices/injection/app/user/api/entity/user.pb.go
+36 −29 practices/injection/app/user/api/user/v1/user.pb.go
+10 −4 practices/injection/app/user/api/user/v1/user_grpc.pb.go
+0 −0 practices/injection/app/user/hack/config.yaml
+0 −0 practices/injection/app/user/internal/cmd/cmd.go
+2 −2 practices/injection/app/user/internal/cmd/cmd_server.go
+0 −0 practices/injection/app/user/internal/cmd/cmd_worker.go
+0 −0 practices/injection/app/user/internal/consts/consts.go
+78 −0 practices/injection/app/user/internal/controller/user/user.go
+108 −0 practices/injection/app/user/internal/controller/user/user_test.go
+32 −16 practices/injection/app/user/internal/dao/user/user.go
+1 −1 practices/injection/app/user/internal/dao/user/user_test.go
+0 −0 practices/injection/app/user/internal/model/.gitkeep
+10 −0 practices/injection/app/user/internal/model/entity/user.go
+114 −0 practices/injection/app/user/internal/service/user/user.go
+1 −1 practices/injection/app/user/internal/service/user/user_test.go
+1 −1 practices/injection/app/user/main.go
+0 −0 practices/injection/app/user/manifest/config/config.yaml
+1 −1 practices/injection/app/user/manifest/deploy/kustomize/base/configmap.yaml
+8 −8 practices/injection/app/user/manifest/deploy/kustomize/base/deployment.yaml
+0 −0 practices/injection/app/user/manifest/deploy/kustomize/base/kustomization.yaml
+2 −2 practices/injection/app/user/manifest/deploy/kustomize/base/service.yaml
+1 −1 practices/injection/app/user/manifest/deploy/kustomize/overlays/develop/configmap.yaml
+2 −2 practices/injection/app/user/manifest/deploy/kustomize/overlays/develop/deployment.yaml
+0 −0 practices/injection/app/user/manifest/deploy/kustomize/overlays/develop/kustomization.yaml
+1 −1 practices/injection/app/user/manifest/deploy/kustomize/overlays/product/configmap.yaml
+2 −2 practices/injection/app/user/manifest/deploy/kustomize/overlays/product/deployment.yaml
+0 −0 practices/injection/app/user/manifest/deploy/kustomize/overlays/product/kustomization.yaml
+0 −0 practices/injection/app/user/manifest/docker/Dockerfile
+0 −0 practices/injection/app/user/manifest/docker/docker.sh
+12 −0 practices/injection/app/user/manifest/protobuf/entity/user.proto
+62 −0 practices/injection/app/user/manifest/protobuf/user/v1/user.proto
+60 −2 practices/injection/utility/injection/injection.go
+1 −1 practices/injection/utility/injection/injection_grpc_clients.go
+0 −67 practices/injection/utility/injection/injection_helper.go
2 changes: 1 addition & 1 deletion net/gclient/gclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 1 addition & 10 deletions net/gclient/gclient_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion util/gconv/gconv_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
Loading