Example #1
0
func main() {

	dataController := new(controllers.DataController)
	manifestController := new(controllers.ManifestController)

	goweb.MapFunc("/api", func(cx *goweb.Context) {
		cx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
		cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
		cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
		cx.RespondWithOK()
	}, OptionsMethod)
	goweb.MapFunc("/api/{model}/{id}", func(cx *goweb.Context) {
		cx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
		cx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
		cx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
		cx.RespondWithOK()
	}, OptionsMethod)
	goweb.MapRest("/api/manifest", manifestController)
	goweb.MapRest("/api/{model}", dataController)

	goweb.ConfigureDefaultFormatters()
	goweb.ListenAndServe(":9000")

}
Example #2
0
func main() {
	// Setup mongodb connection
	var err error
	mSession, err = mgo.Dial(mHost)
	if err != nil {
		panic(err)
	}
	defer mSession.Close()

	// Optional. Switch the session to a monotonic behavior.
	mSession.SetMode(mgo.Monotonic, true)

	// map the RESTful resources
	goweb.MapRest("/api/{collection}", new(ApiController))

	goweb.ConfigureDefaultFormatters()
	goweb.ListenAndServe(":8080")
}