Alanxtl commented on code in PR #1112:
URL: https://github.com/apache/dubbo-go-samples/pull/1112#discussion_r3620371238


##########
triple_header_trailer/go-client/cmd/main.go:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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"
+       "fmt"
+       "net/http"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3/client"
+       _ "dubbo.apache.org/dubbo-go/v3/imports"
+       triple "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
+
+       "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+       greet "github.com/apache/dubbo-go-samples/triple_header_trailer/proto"
+)
+
+const (
+       tokenHeader       = "X-Sample-Token"
+       modeHeader        = "X-Sample-Mode"
+       unaryResponseKey  = "X-Unary-Response"
+       unaryTrailerKey   = "X-Unary-Trailer"
+       streamResponseKey = "X-Stream-Response"
+       streamTrailerKey  = "X-Stream-Trailer"
+)
+
+func main() {
+       cli, err := client.NewClient(
+               client.WithClientURL("tri://127.0.0.1:20000"),
+       )
+       if err != nil {
+               panic(err)
+       }
+
+       svc, err := greet.NewGreetService(cli)
+       if err != nil {
+               panic(err)
+       }
+
+       if err := testUnary(svc); err != nil {
+               panic(err)
+       }
+       if err := testBidiStream(svc); err != nil {
+               panic(err)
+       }
+       if err := testClientStream(svc); err != nil {
+               panic(err)
+       }
+       if err := testServerStream(svc); err != nil {
+               panic(err)
+       }
+}
+
+func testUnary(cli greet.GreetService) error {
+       var responseHeader http.Header
+       var responseTrailer http.Header
+       resp, err := cli.Greet(
+               outgoingContext("unary-token"),
+               &greet.GreetRequest{Name: "unary"},
+               client.WithResponseHeader(&responseHeader),
+               client.WithResponseTrailer(&responseTrailer),
+       )
+       if err != nil {
+               return err
+       }
+       if err := requireGreeting(resp.Greeting, "hello unary, 
token=unary-token, modes=metadata,trailer-demo"); err != nil {
+               return err
+       }
+       logger.Infof("unary response: %s", resp.Greeting)
+       logger.Infof("unary response header %s=%v", unaryResponseKey, 
responseHeader.Values(unaryResponseKey))
+       logger.Infof("unary response trailer %s=%v", unaryTrailerKey, 
responseTrailer.Values(unaryTrailerKey))
+       if err := requireHeader(responseHeader, unaryResponseKey, 
"unary-header"); err != nil {
+               return err
+       }
+       return requireHeader(responseTrailer, unaryTrailerKey, "unary-trailer")
+}
+
+func testBidiStream(cli greet.GreetService) error {
+       stream, err := cli.GreetStream(outgoingContext("bidi-token"))
+       if err != nil {
+               return err
+       }
+
+       if err := stream.Send(&greet.GreetStreamRequest{Name: "bidi"}); err != 
nil {
+               return err
+       }
+       resp, err := stream.Recv()
+       if err != nil {
+               return err
+       }
+       if resp == nil {
+               return fmt.Errorf("unexpected empty bidi response")
+       }
+       if err := requireGreeting(resp.Greeting, "bidi hello bidi, 
token=bidi-token"); err != nil {
+               return err
+       }
+       logger.Infof("bidi response: %s", resp.Greeting)
+       logger.Infof("bidi response header %s=%v", streamResponseKey, 
stream.ResponseHeader().Values(streamResponseKey))
+
+       if err := stream.CloseRequest(); err != nil {
+               return err
+       }
+       if err := stream.CloseResponse(); err != nil {
+               return err
+       }
+       logger.Infof("bidi response trailer %s=%v", streamTrailerKey, 
stream.ResponseTrailer().Values(streamTrailerKey))
+       return requireHeader(stream.ResponseTrailer(), streamTrailerKey, 
"bidi-trailer")
+}
+
+func testClientStream(cli greet.GreetService) error {
+       stream, err := 
cli.GreetClientStream(outgoingContext("client-stream-token"))
+       if err != nil {
+               return err
+       }
+
+       for _, name := range []string{"client", "stream"} {
+               if err := stream.Send(&greet.GreetClientStreamRequest{Name: 
name}); err != nil {

Review Comment:
   done



##########
triple_header_trailer/go-client/cmd/main.go:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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"
+       "fmt"
+       "net/http"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3/client"
+       _ "dubbo.apache.org/dubbo-go/v3/imports"
+       triple "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
+
+       "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+       greet "github.com/apache/dubbo-go-samples/triple_header_trailer/proto"
+)
+
+const (
+       tokenHeader       = "X-Sample-Token"
+       modeHeader        = "X-Sample-Mode"
+       unaryResponseKey  = "X-Unary-Response"
+       unaryTrailerKey   = "X-Unary-Trailer"
+       streamResponseKey = "X-Stream-Response"
+       streamTrailerKey  = "X-Stream-Trailer"
+)
+
+func main() {
+       cli, err := client.NewClient(
+               client.WithClientURL("tri://127.0.0.1:20000"),
+       )
+       if err != nil {
+               panic(err)
+       }
+
+       svc, err := greet.NewGreetService(cli)
+       if err != nil {
+               panic(err)
+       }
+
+       if err := testUnary(svc); err != nil {
+               panic(err)
+       }
+       if err := testBidiStream(svc); err != nil {
+               panic(err)
+       }
+       if err := testClientStream(svc); err != nil {
+               panic(err)
+       }
+       if err := testServerStream(svc); err != nil {
+               panic(err)
+       }
+}
+
+func testUnary(cli greet.GreetService) error {
+       var responseHeader http.Header
+       var responseTrailer http.Header
+       resp, err := cli.Greet(
+               outgoingContext("unary-token"),
+               &greet.GreetRequest{Name: "unary"},
+               client.WithResponseHeader(&responseHeader),
+               client.WithResponseTrailer(&responseTrailer),
+       )
+       if err != nil {
+               return err
+       }
+       if err := requireGreeting(resp.Greeting, "hello unary, 
token=unary-token, modes=metadata,trailer-demo"); err != nil {
+               return err
+       }
+       logger.Infof("unary response: %s", resp.Greeting)
+       logger.Infof("unary response header %s=%v", unaryResponseKey, 
responseHeader.Values(unaryResponseKey))
+       logger.Infof("unary response trailer %s=%v", unaryTrailerKey, 
responseTrailer.Values(unaryTrailerKey))
+       if err := requireHeader(responseHeader, unaryResponseKey, 
"unary-header"); err != nil {
+               return err
+       }
+       return requireHeader(responseTrailer, unaryTrailerKey, "unary-trailer")
+}
+
+func testBidiStream(cli greet.GreetService) error {
+       stream, err := cli.GreetStream(outgoingContext("bidi-token"))
+       if err != nil {
+               return err
+       }
+
+       if err := stream.Send(&greet.GreetStreamRequest{Name: "bidi"}); err != 
nil {

Review Comment:
   doen



-- 
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