Beispiel #1
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")
}
Beispiel #2
0
func main() {

	opts := levigo.NewOptions()
	opts.SetCreateIfMissing(true)
	ro := levigo.NewReadOptions()
	wo := levigo.NewWriteOptions()

	db, err := levigo.Open("slugs.leveldb", opts)
	if err == nil {
	}
	goweb.ConfigureDefaultFormatters()
	goweb.MapFunc("/{slug}", func(c *goweb.Context) {

		key := []byte(c.PathParams["slug"])

		if c.IsGet() {
			fmt.Printf("GET %s\n", c.PathParams["slug"])
			data, err := db.Get(ro, key)
			if err == nil {
				if data == nil {
					c.WriteResponse("Not found", 404)
				} else {
					c.ResponseWriter.Header().Set("Location", string(data))
					c.WriteResponse(data, 307)
				}
			}
		}

		if c.IsPost() {
			bodyio := bufio.NewReader(c.Request.Body)
			body, err := bodyio.ReadString('\n')
			if err == nil {
			}

			fmt.Printf("POST %s %s\n", key, body)
			err = db.Put(wo, key, []byte(body))
		}

	})

	fmt.Println("ready")
	goweb.ListenAndServe(":8080")
	fmt.Println("bye bye")
}
Beispiel #3
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")

}