Пример #1
0
// getHandleCSConfigFunc returns a func which handles requests to the CSConfig endpoint,
// returning the encoded CSConfig data for the requested host.
func getHandleCSConfigFunc(db *sqlx.DB) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		setHeaders(w, []api.ApiMethod{api.GET})
		enc := json.NewEncoder(w)
		vars := mux.Vars(r)
		hostName := vars["hostname"]
		portStr := vars["port"]
		port, err := strconv.Atoi(portStr)
		if err != nil {
			enc.Encode(struct {
				Error string `json:"error"`
			}{Error: err.Error()})
			return
		}

		resp, err := csconfig.GetCSConfig(hostName, int64(port), db)
		if err != nil {
			enc.Encode(struct {
				Error string `json:"error"`
			}{Error: err.Error()})
		} else {
			enc.Encode(resp)
		}
	}
}
Пример #2
0
// getHandleCSConfigFunc returns a func which handles requests to the CSConfig endpoint,
// returning the encoded CSConfig data for the requested host.
func getHandleCSConfigFunc(db *sqlx.DB) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		vars := mux.Vars(r)
		hostName := vars["hostname"]
		resp, _ := csconfig.GetCSConfig(hostName, db)
		enc := json.NewEncoder(w)
		enc.Encode(resp)
	}
}