Example #1
0
func (cc CustomerController) GetCustomer(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	id := p.ByName("id")

	if !bson.IsObjectIdHex(id) {
		w.WriteHeader(404)
		return
	}

	oid := bson.ObjectIdHex(id)

	opt := models.OptKey{}
	opt.Opt = "GET"
	opt.Id = oid
	optj, _ := json.Marshal(opt)

	cj, err := zmqClient.Req_bytes(zmq_broker_frontend_url_port, optj)

	if err != nil {
		log.Println(id, err.Error())
		w.WriteHeader(404)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(200)
	fmt.Fprintf(w, "%s", cj)
}
Example #2
0
func (cc CustomerController) RemoveCustomer(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	id := p.ByName("id")

	if !bson.IsObjectIdHex(id) {
		w.WriteHeader(404)
		return
	}

	oid := bson.ObjectIdHex(id)

	opt := models.OptKey{}
	opt.Opt = "GET"
	opt.Id = oid
	optj, _ := json.Marshal(opt)

	if _, err := zmqClient.Req_bytes(zmq_broker_frontend_url_port, optj); err != nil {
		log.Println(id, err.Error())
		w.WriteHeader(404)
		return
	}
	w.WriteHeader(200)
}