func main() { //json.NewDecoder(r.Body).Decode(&c) jstr := `{"firstName": "Infosys", "lastName": "Inc.", "emailAddress": "*****@*****.**", "Street": "Canary Wharf", "City": "London", "Postcode": "E14 5NP"}` c := models.Customer{} json.Unmarshal([]byte(jstr), &c) c.Id = bson.NewObjectId() //cj, _ := json.Marshal(c) opt := models.OptCinfo{} opt.Opt = "INSERT" opt.Customer = &c optj1, _ := json.Marshal(opt) //reply, _ := zmq_req_byte("tcp://localhost:5555", optj1) //zmq_req("tcp://localhost:5555", string(optj1)) reply, _ := zmqClient.Req_bytes("tcp://localhost:5555", optj1) log.Println(42, reply) c2 := models.Customer{} json.Unmarshal(reply, &c2) log.Println(41, c2) }
//send customer info to backend service via zmq func (cc CustomerController) CreateCustomer(w http.ResponseWriter, r *http.Request, p httprouter.Params) { c := models.Customer{} json.NewDecoder(r.Body).Decode(&c) //c.Id = bson.NewObjectId() opt := models.OptCinfo{} opt.Opt = "INSERT" opt.Customer = &c optj, _ := json.Marshal(opt) reply, err := zmqClient.Req_bytes(zmq_broker_frontend_url_port, optj) if err != nil { log.Println(c.Id, err.Error()) w.WriteHeader(404) return } cj, _ := json.Marshal(reply) w.Header().Set("Content-Type", "application/json") w.WriteHeader(201) fmt.Fprintf(w, "%s", cj) }