convert JSON to protobuf
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
95b4b77b27
commit
fb698301e4
|
@ -4,8 +4,12 @@ import "fmt"
|
|||
import "log"
|
||||
import "net/http"
|
||||
import "io/ioutil"
|
||||
import "strings"
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
import "github.com/golang/protobuf/jsonpb"
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
// spew.Dump(r)
|
||||
|
@ -13,6 +17,17 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||
log.Printf("handler: fucking unknown path")
|
||||
}
|
||||
|
||||
func JSONtoPB(a string) pb.Account {
|
||||
sets := pb.Account{}
|
||||
|
||||
err := jsonpb.Unmarshal(strings.NewReader(string(a)), &sets)
|
||||
if err != nil {
|
||||
log.Println("jsonpb.Unmarshal() ERROR =", err)
|
||||
}
|
||||
spew.Dump(sets)
|
||||
return sets
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("listen on :9000")
|
||||
|
||||
|
@ -34,4 +49,9 @@ func handler2(w http.ResponseWriter, r *http.Request) {
|
|||
j := string(body)
|
||||
log.Println("body =", j)
|
||||
log.Println("err =", err)
|
||||
|
||||
account := JSONtoPB(string(body))
|
||||
account.Token = "testing a token"
|
||||
|
||||
log.Println("account =", account)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue