Ejemplo n.º 1
0
func queryServerIDRetriever(w http.ResponseWriter, ids []string) {
	s := make(chan map[string]string, len(ids))
	db.ServerDB.GetHostsAndGameFromIDAPIQuery(s, ids)
	hostsgames := <-s
	if len(hostsgames) == 0 {
		w.WriteHeader(http.StatusOK)
		if err := json.NewEncoder(w).Encode(models.GetDefaultServerList()); err != nil {
			writeJSONEncodeError(w, err)
		}
		return
	}
	serverlist, err := steam.Query(hostsgames)
	if err != nil {
		setNotFoundAndLog(w, err)
		if err := json.NewEncoder(w).Encode(models.GetDefaultServerList()); err != nil {
			writeJSONEncodeError(w, err)
			return
		}
		return
	}
	if err := json.NewEncoder(w).Encode(serverlist); err != nil {
		writeJSONEncodeError(w, err)
		logger.LogWebError(err)
	}
}
Ejemplo n.º 2
0
// setNotFoundAndLog sets the error code of the underlying writer to 404 (not found)
// and internally logs the error.
func setNotFoundAndLog(w http.ResponseWriter, err error) {
	w.WriteHeader(http.StatusNotFound)
	logger.LogWebError(err)
}