<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                客戶端 === 實現pb.go客戶端接口 ~~~ type AddServiceClient interface { Add(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) Multiply(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) } ~~~ 實踐 ~~~ package main import ( "GRPC-Study/demo1/proto" "fmt" "github.com/gin-gonic/gin" "google.golang.org/grpc" "net/http" "strconv" ) func main() { // 創建一個tcp撥號 conn, e := grpc.Dial(":9001", grpc.WithInsecure()) // grpc.WithInsecure() 不安全的傳輸 if e != nil { panic(e.Error()) } client := proto.NewAddServiceClient(conn)// 注冊上去 app := gin.Default() app.GET("/add/:a/:b", middlerware,func(ctx *gin.Context) { a := ctx.MustGet("a").(int64) b := ctx.MustGet("b").(int64) req := &proto.Request{A: a, B: b} if response, i := client.Add(ctx, req);i != nil { // 發送rpc請求 ctx.JSON(http.StatusInternalServerError,gin.H{ "error":"Internal Server Error", }) }else{ ctx.JSON(http.StatusOK,gin.H{ "result":fmt.Sprint(response.Result), }) } }) app.GET("/mult/:a/:b", middlerware,func(ctx *gin.Context) { a := ctx.MustGet("a").(int64) b := ctx.MustGet("b").(int64) req := &proto.Request{A: a, B: b} if response, i := client.Multiply(ctx, req);i != nil { // 發送rpc請求 ctx.JSON(http.StatusInternalServerError,gin.H{ "error":"Internal Server Error", }) }else{ ctx.JSON(http.StatusOK,gin.H{ "result":fmt.Sprint(response.Result), }) } }) if e := app.Run(":9002");e != nil { panic(e.Error()) } } // 對a,b 參數 做個驗證 func middlerware(ctx *gin.Context) { a, err := strconv.ParseInt(ctx.Param("a"), 10, 64) if err != nil { ctx.JSON(http.StatusBadRequest,gin.H{ "err":"Bad Request", }) ctx.Abort() return } b, err := strconv.ParseInt(ctx.Param("b"), 10, 64) if err != nil { ctx.JSON(http.StatusBadRequest,gin.H{ "err":"Bad Request", }) ctx.Abort() return } ctx.Set("a",a) ctx.Set("b",b) } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看