gin protobuf客户端测试

gin protobuf客户端测试

// clientGIN project main.go
package main

import (
    "clientGIN/model"
    "fmt"
    "io/ioutil"
    "net/http"

    "google.golang.org/protobuf/proto"
)

func main() {
    resp, err := http.Post("http://localhost:1234/protobuf/units/select", "application/x-protobuffer", nil)
    if err != nil {
        fmt.Println(err)
    } else {
        defer resp.Body.Close()
        body, err := ioutil.ReadAll(resp.Body)
        if err != nil {
            fmt.Println(err)
        } else {
            var dws model.TunitArray
            proto.Unmarshal(body, &dws)
            for _, dw := range dws.Tunits {
                fmt.Println(dw.Unitid, dw.Unitname)
            }
        }

    }
}

 

posted @ 2022-07-31 11:43  delphi中间件  阅读(98)  评论(0编辑  收藏  举报