AlexStocks commented on code in PR #1109:
URL: https://github.com/apache/dubbo-go-samples/pull/1109#discussion_r3628372470


##########
rpc/rest/go-client/cmd/client.go:
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+       "context"
+       "flag"
+       "time"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3"
+       "dubbo.apache.org/dubbo-go/v3/client"
+       _ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/failover"
+       _ "dubbo.apache.org/dubbo-go/v3/cluster/cluster/zoneaware"
+       _ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random"
+       _ "dubbo.apache.org/dubbo-go/v3/cluster/router/condition"
+       "dubbo.apache.org/dubbo-go/v3/common/constant"
+       _ "dubbo.apache.org/dubbo-go/v3/filter/graceful_shutdown"
+       _ "dubbo.apache.org/dubbo-go/v3/metadata/mapping/metadata"
+       _ "dubbo.apache.org/dubbo-go/v3/metadata/report/nacos"
+       _ "dubbo.apache.org/dubbo-go/v3/metadata/report/zookeeper"
+       _ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
+       _ "dubbo.apache.org/dubbo-go/v3/protocol/rest"
+       _ "dubbo.apache.org/dubbo-go/v3/registry/directory"
+       _ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
+       _ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
+       _ "dubbo.apache.org/dubbo-go/v3/registry/servicediscovery"
+       _ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper"
+
+       "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+       "github.com/apache/dubbo-go-samples/rpc/rest/api"
+)
+
+func main() {
+       registryName := flag.String("registry", api.DefaultRegistry, "registry 
mode: direct, zookeeper, or nacos")
+       registryType := flag.String("registry-type", api.DefaultRegistryType, 
"registry type: interface, service, or all")
+       flag.Parse()
+
+       api.InstallConsumerRestConfig()
+
+       instanceOpts := []dubbo.InstanceOption{
+               dubbo.WithName(api.ClientAppName),
+       }
+       registryOpts, err := api.RegistryOptions(*registryName, *registryType)
+       if err != nil {
+               panic(err)
+       }
+       if len(registryOpts) > 0 {
+               instanceOpts = append(instanceOpts, 
dubbo.WithRegistry(registryOpts...))
+       }
+
+       ins, err := dubbo.NewInstance(instanceOpts...)
+       if err != nil {
+               panic(err)
+       }
+
+       clientOpts := []client.ClientOption{
+               client.WithClientNoCheck(),
+               client.WithClientRequestTimeout(5 * time.Second),
+       }
+       if *registryName == api.RegistryDirect || *registryName == "" {
+               clientOpts = append(clientOpts, 
client.WithClientURL("rest://127.0.0.1:20080"))
+       }
+
+       cli, err := ins.NewClient(clientOpts...)
+       if err != nil {
+               panic(err)
+       }
+
+       conn, err := cli.Dial(
+               api.InterfaceName,
+               client.WithProtocol(constant.RESTProtocol),
+       )
+       if err != nil {
+               panic(err)
+       }
+
+       resp := new(api.GreetingResponse)
+       err = conn.CallUnary(
+               context.Background(),
+               []any{
+                       101,
+                       "dubbo-go",
+                       "trace-rest-basic",
+                       &api.GreetingRequest{Message: 
"body-from-dubbo-rest-client"},
+               },
+               resp,
+               api.MethodGetGreeting,
+       )
+       if err != nil {
+               logger.Error(err)
+               panic(err)
+       }
+
+       logger.Infof("REST response: userID=%d name=%s traceID=%s message=%s 
greeting=%q\n",

Review Comment:
   [P1] 让集成客户端对响应内容失败闭环
   
   `integrate_test.sh` 只根据 Go client 的退出码判断该 sample 
是否通过,而这里仅打印响应、不校验任何字段。我在镜像副本中把服务端 `Greeting` 固定改为 `BROKEN_MUTATION` 后,现有 client 
仍以退出码 0 结束,因此路径、query、header、body 映射或服务端返回值发生回归时 CI 仍可能保持绿色。请对 
`UserID`、`Name`、`TraceID`、`Message`、`Greeting` 做精确断言并在不匹配时返回非 0;由于 
consumer/provider 共用同一份 REST config,还应增加一次原生 HTTP 请求,固定验证 README 声明的 POST 
路径、参数名、请求头和 JSON body。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to