Ejemplo n.º 1
0
func (fh *ForwardHandler) HandleAppEvent(w http.ResponseWriter, body []byte) {
	event, err := events.ParseEvent(body)
	if err != nil {
		w.WriteHeader(500)
		fmt.Fprintln(w, err.Error())
		log.Printf("[ERROR] body generated error: %s", err.Error())
		return
	}

	resp := ""
	respCode := 200
	for _, app := range event.Apps() {
		err = fh.consul.UpdateApp(app)
		if err != nil {
			resp += err.Error() + "\n"
			log.Printf("[ERROR] response generated error: %s", err.Error())
			respCode = 500
		}
	}

	if resp == "" {
		resp = "OK\n"
	}

	w.WriteHeader(respCode)
	fmt.Fprint(w, resp)
}
Ejemplo n.º 2
0
func (fh *ForwardHandler) HandleTerminationEvent(body []byte) error {
	event, err := events.ParseEvent(body)
	if err != nil {
		return err
	}

	// app_terminated_event only has one app in it, so we will just take care of
	// it instead of looping
	return fh.consul.DeleteApp(event.Apps()[0])
}
Ejemplo n.º 3
0
func (fh *ForwardHandler) HandleAppEvent(body []byte) error {
	event, err := events.ParseEvent(body)
	if err != nil {
		return err
	}

	for _, app := range event.Apps() {
		err = fh.consul.UpdateApp(app)
		if err != nil {
			return err
		}
	}
	return nil
}
Ejemplo n.º 4
0
func (fh *ForwardHandler) HandleTerminationEvent(w http.ResponseWriter, body []byte) {
	event, err := events.ParseEvent(body)
	if err != nil {
		w.WriteHeader(500)
		fmt.Fprintln(w, err.Error())
		log.Printf("[ERROR] body generated error: %s", err.Error())
		return
	}

	// app_terminated_event only has one app in it, so we will just take care of
	// it instead of looping
	err = fh.consul.DeleteApp(event.Apps()[0])
	if err != nil {
		w.WriteHeader(500)
		fmt.Fprintln(w, err.Error())
		log.Printf("[ERROR] response generated error: %s", err.Error())
	} else {
		w.WriteHeader(200)
		fmt.Fprintln(w, "OK")
	}
}