You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
700 B

package main
import (
"encoding/json"
"fmt"
"net/http"
"gopkg.in/mgo.v2/bson"
)
type Routes []Route
var routes = Routes{
Route{
"Index",
"GET",
"/",
Index,
},
Route{
"GetAllCells",
"Get",
"/allcells",
GetAllCells,
},
}
//ROUTES
func Index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "ask for cells in /r")
//http.FileServer(http.Dir("./web"))
}
func GetAllCells(w http.ResponseWriter, r *http.Request) {
ipFilter(w, r)
cells := []CellModel{}
iter := cellCollection.Find(bson.M{}).Limit(10000).Iter()
err := iter.All(&cells)
//convert []cells struct to json
jsonCells, err := json.Marshal(cells)
check(err)
fmt.Fprintln(w, string(jsonCells))
}