コード例 #1
0
ファイル: api.go プロジェクト: mattking17/shiftbase
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")

}
コード例 #2
0
ファイル: goplay.go プロジェクト: intel352/go-play
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")
}