write out the protobuf

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-25 17:36:35 -07:00
parent aff660822e
commit 4fbfc3dde7
1 changed files with 18 additions and 1 deletions

View File

@ -59,10 +59,27 @@ func handler2(w http.ResponseWriter, r *http.Request) {
log.Println("err =", err)
// change the JSON int a protobuf
account := JSONtoPB(string(body))
var account pb.Account
account = JSONtoPB(string(body))
account.Token = "testing a token"
log.Println("account =", account)
// Add all the HTTP headers to the Account protobuf
for name, headers := range r.Header {
log.Println("handler2() name =", name)
log.Println("handler2() headers =", headers)
name = strings.ToLower(name)
for _, h := range headers {
log.Println("handler2() h =", h)
// create a new Account_httpHeader
var request pb.Account_HttpHeader
request.Name = name
request.Value = h
account.HttpHeaders = append(account.HttpHeaders, &request)
}
}
// change it back to JSON
marshaler := &jsonpb.Marshaler{}
stuff, _ := marshaler.MarshalToString(&account)