Example #1
0
func statusHandler(w http.ResponseWriter, r *http.Request) {
	name := r.URL.Query().Get("name")
	if len(name) == 0 {
		w.WriteHeader(http.StatusBadRequest)
		w.Write(([]byte)("Missing or empty parameter\n"))
		return
	}

	if cb, _, err := hystrix.GetCircuit(name); err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write(([]byte)("Can get Circuit Breaker\n"))
	} else {
		w.WriteHeader(http.StatusOK)
		allow := "Allow:No\n"
		if cb.AllowRequest() {
			allow = "Allow:Yes\n"
		}
		isOpen := "Opened:No\n"
		if cb.IsOpen() {
			isOpen = "Opened:Yes\n"
		}

		w.Write(([]byte)(allow + isOpen))
	}
}
Example #2
0
func closeHandler(w http.ResponseWriter, r *http.Request) {
	name := r.URL.Query().Get("name")
	if len(name) == 0 {
		w.WriteHeader(http.StatusBadRequest)
		w.Write(([]byte)("Missing or empty parameter\n"))
		return
	}

	if cb, _, err := hystrix.GetCircuit(name); err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write(([]byte)("Can get Circuit Breaker\n"))
	} else {
		cb.ReportEvent([]string{"success"}, time.Now(), 0)

		w.WriteHeader(http.StatusOK)
		w.Write(([]byte)("Closed.\n"))
	}
}
Example #3
0
func toggleOpenHandler(w http.ResponseWriter, r *http.Request) {
	name := r.URL.Query().Get("name")
	tg := r.URL.Query().Get("value")
	if len(name) == 0 || (tg != "true" && tg != "false") {
		w.WriteHeader(http.StatusBadRequest)
		w.Write(([]byte)("Missing or empty parameter\n"))
		return
	}

	if cb, _, err := hystrix.GetCircuit(name); err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write(([]byte)("Can get Circuit Breaker\n"))
	} else {
		cb.ToggleForceOpen(tg == "true")
		cb.AllowRequest()
		w.WriteHeader(http.StatusOK)
		w.Write(([]byte)("Done.\n"))

		log.Printf("%#v", *cb)

	}
}