Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Mar 3, 2025
2 parents f97a6fa + f4074cd commit 48cf952
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
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 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)
}

0 comments on commit 48cf952

Please sign in to comment.