This is an automated email from the ASF dual-hosted git repository.
Alanxtl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
The following commit(s) were added to refs/heads/main by this push:
new 0d4d76a6 fix(task/shop): 修复商城 demo 灰度路由相关的 2 个问题 (#1111)
0d4d76a6 is described below
commit 0d4d76a649aa67b0f3c9729809f65bd849ac6ddf
Author: xxs <[email protected]>
AuthorDate: Fri Jun 12 16:25:54 2026 +0800
fix(task/shop): 修复商城 demo 灰度路由相关的 2 个问题 (#1111)
* fix(task/shop): swap CheckItem and CheckItemGray implementations
CheckItem was attaching gray tag (actual gray routing) while CheckItemGray
was using plain context (actual plain routing). The implementations were
reversed relative to their naming.
- CheckItem: use plain context.Background() for normal routing
- CheckItemGray: attach dubbo.tag=gray + dubbo.force.tag=true for gray
routing
* feat(task/shop): add gray tag to v2 services for tag routing
v2 services had no gray tag, making them indistinguishable from v1 in the
registry. Tag routing cannot route to gray providers without proper tags.
Add dubbo.WithTag("gray") to comment-v2, detail-v2, and order-v2,
following the same pattern as the official router/tag sample.
* fix: use dubbo-go constants instead of hardcoded strings for tag routing
Address Copilot review comment: replace hardcoded "dubbo.tag" and
"dubbo.force.tag" strings with constant.Tagkey and constant.ForceUseTag
for consistency with other tag-router samples.
---
task/shop/comment/server_v2/cmd/server.go | 1 +
task/shop/detail/server_v2/cmd/server.go | 1 +
task/shop/frontend/server_v1/server.go | 18 +++++++++---------
task/shop/order/server_v2/cmd/server.go | 1 +
4 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/task/shop/comment/server_v2/cmd/server.go
b/task/shop/comment/server_v2/cmd/server.go
index 7d2f7d00..2e08f26d 100644
--- a/task/shop/comment/server_v2/cmd/server.go
+++ b/task/shop/comment/server_v2/cmd/server.go
@@ -45,6 +45,7 @@ func (c *CommentProvider) GetComment(ctx context.Context,
itemName *api.CommentR
func main() {
ins, err := dubbo.NewInstance(
dubbo.WithName("shop-comment"),
+ dubbo.WithTag("gray"),
dubbo.WithRegistry(
registry.WithZookeeper(),
registry.WithAddress("127.0.0.1:2181"),
diff --git a/task/shop/detail/server_v2/cmd/server.go
b/task/shop/detail/server_v2/cmd/server.go
index 56c90726..fc106c6c 100644
--- a/task/shop/detail/server_v2/cmd/server.go
+++ b/task/shop/detail/server_v2/cmd/server.go
@@ -66,6 +66,7 @@ func (d *DetailProvider) DeductStock(ctx context.Context, req
*api.DeductStockRe
func main() {
ins, err := dubbo.NewInstance(
dubbo.WithName("shop-detail"),
+ dubbo.WithTag("gray"),
dubbo.WithRegistry(
registry.WithZookeeper(),
registry.WithAddress("127.0.0.1:2181"),
diff --git a/task/shop/frontend/server_v1/server.go
b/task/shop/frontend/server_v1/server.go
index 01eb5d26..b16f11c1 100644
--- a/task/shop/frontend/server_v1/server.go
+++ b/task/shop/frontend/server_v1/server.go
@@ -126,14 +126,7 @@ func (s *ShopServiceProvider) CheckItem(sku int64,
username string) (*detailAPI.
Sku: sku,
UserName: username,
}
- // add tag
- ctx := context.Background()
- atm := map[string]string{
- "dubbo.tag": "gray",
- "dubbo.force.tag": "true",
- }
- ctx = context.WithValue(ctx, constant.AttachmentKey, atm)
- return s.detailService.GetItem(ctx, req)
+ return s.detailService.GetItem(context.Background(), req)
}
func (s *ShopServiceProvider) CheckItemGray(sku int64, username string)
(*detailAPI.Item, error) {
@@ -141,7 +134,14 @@ func (s *ShopServiceProvider) CheckItemGray(sku int64,
username string) (*detail
Sku: sku,
UserName: username,
}
- return s.detailService.GetItem(context.Background(), req)
+ // add tag for gray routing
+ ctx := context.Background()
+ atm := map[string]string{
+ constant.Tagkey: "gray",
+ constant.ForceUseTag: "true",
+ }
+ ctx = context.WithValue(ctx, constant.AttachmentKey, atm)
+ return s.detailService.GetItem(ctx, req)
}
func (s *ShopServiceProvider) SubmitOrder(sku int64, count int, address,
phone, receiver string) (*orderAPI.OrderResp, error) {
diff --git a/task/shop/order/server_v2/cmd/server.go
b/task/shop/order/server_v2/cmd/server.go
index f2514201..ea360140 100644
--- a/task/shop/order/server_v2/cmd/server.go
+++ b/task/shop/order/server_v2/cmd/server.go
@@ -56,6 +56,7 @@ func (o *OrderProvider) SubmitOrder(ctx context.Context, req
*api.OrderReq) (*ap
func main() {
ins, err := dubbo.NewInstance(
dubbo.WithName("shop-order"),
+ dubbo.WithTag("gray"),
dubbo.WithRegistry(
registry.WithZookeeper(),
registry.WithAddress("127.0.0.1:2181"),