示例#1
0
func getServerIDs(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")

	hosts := getQStringValues(r.URL.Query(), qsGetServerIDs)
	for _, v := range hosts {
		logger.WriteDebug("host slice values: %s", v)
		// basically require at least 2 octets
		if len(v) < 4 {
			w.WriteHeader(http.StatusBadRequest)
			writeJSONResponse(w, models.GetDefaultServerID())
			return
		}
	}
	getServerIDRetriever(w, hosts)
}
示例#2
0
func getServerIDRetriever(w http.ResponseWriter, hosts []string) {
	m := make(chan *models.DbServerID, 1)
	go db.ServerDB.GetIDsAPIQuery(m, hosts)
	ids := <-m
	if len(ids.Servers) > 0 {
		if err := json.NewEncoder(w).Encode(ids); err != nil {
			writeJSONEncodeError(w, err)
			return
		}
	} else {
		w.WriteHeader(http.StatusOK)
		if err := json.NewEncoder(w).Encode(models.GetDefaultServerID()); err != nil {
			writeJSONEncodeError(w, err)
			return
		}
	}
}