From 4fbfc3dde767f6aecc60e8aab506857dda2d8024 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 25 May 2019 17:36:35 -0700 Subject: [PATCH] write out the protobuf Signed-off-by: Jeff Carr --- signup.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/signup.go b/signup.go index 5c33f14..8043d3e 100644 --- a/signup.go +++ b/signup.go @@ -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)