boskos/boskos.go
func handleMetric(r *ranch.Ranch) http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {
		logrus.WithField("handler", "handleMetric").Infof("From %v", req.RemoteAddr)

		if req.Method != http.MethodGet {
			logrus.Warningf("[BadRequest]method %v, expect GET", req.Method)
			http.Error(res, "/metric only accepts GET", http.StatusMethodNotAllowed)
			return
		}

		rtype := req.URL.Query().Get("type")
		if rtype == "" {
			msg := "Type must be set in the request."
			logrus.Warning(msg)
			http.Error(res, msg, http.StatusBadRequest)
			return
		}

		metric, err := r.Metric(rtype)
		if err != nil {
			logrus.WithError(err).Errorf("Metric for %s failed", rtype)
			http.Error(res, err.Error(), ErrorToStatus(err))
			return
		}

		js, err := json.Marshal(metric)
		if err != nil {
			logrus.WithError(err).Error("Fail to marshal metric")
			http.Error(res, err.Error(), ErrorToStatus(err))
			return
		}

		res.Header().Set("Content-Type", "application/json")
		res.Write(js)
	}
}
func handleMetric(r *ranch.Ranch) http.HandlerFunc {
	return func(res http.ResponseWriter, req *http.Request) {
		logrus.WithField("handler", "handleMetric").Infof("From %v", req.RemoteAddr)

		if req.Method != http.MethodGet {
			logrus.Warningf("[BadRequest]method %v, expect GET", req.Method)
			http.Error(res, "/metric only accepts GET", http.StatusMethodNotAllowed)
			return
		}

		rtype := req.URL.Query().Get("type")
		if rtype == "" {
			msg := "Type must be set in the request."
			logrus.Warning(msg)
			http.Error(res, msg, http.StatusBadRequest)
			return
		}

		metric, err := r.Metric(rtype)
		if err != nil {
			logrus.WithError(err).Errorf("Metric for %s failed", rtype)
			http.Error(res, err.Error(), ErrorToStatus(err))
			return
		}

		js, err := json.Marshal(metric)
		if err != nil {
			logrus.WithError(err).Error("Fail to marshal metric")
			http.Error(res, err.Error(), ErrorToStatus(err))
			return
		}

		res.Header().Set("Content-Type", "application/json")
		res.Write(js)
	}
}
func handleMetric ( r * ranch . Ranch ) http . HandlerFunc { return func ( res http . ResponseWriter , req * http . Request ) { logrus . WithField ( " " , " " ) . Infof ( " " , req . RemoteAddr ) if req . Method != http . MethodGet { logrus . Warningf ( " " , req . Method ) http . Error ( res , " " , http . StatusMethodNotAllowed ) return } rtype := req . URL . Query ( ) . Get ( " " ) if rtype == " " { msg := " " logrus . Warning ( msg ) http . Error ( res , msg , http . StatusBadRequest ) return } metric , err := r . Metric ( rtype ) if err != nil { logrus . WithError ( err ) . Errorf ( " " , rtype ) http . Error ( res , err . Error ( ) , ErrorToStatus ( err ) ) return } js , err := json . Marshal ( metric ) if err != nil { logrus . WithError ( err ) . Error ( " " ) http . Error ( res , err . Error ( ) , ErrorToStatus ( err ) ) return } res . Header ( ) . Set ( " " , " " ) res . Write ( js ) } }
//  handleMetric: Handler for /metric
//  Method: GET
handleMetric : Handler for / metric Method : GET