func main() { goweb.MapFunc("/", hello) err := goweb.ListenAndServe(":" + os.Getenv("PORT")) if err != nil { panic(err) } }
func main() { goweb.MapFunc("/people/{name}/animals/{animal_name}", func(c *goweb.Context) { fmt.Fprintf(c.ResponseWriter, "Hey %s, your favourite animal is a %s", c.PathParams["name"], c.PathParams["animal_name"]) }) goweb.ListenAndServe(":8080") }
func main() { goweb.MapFunc("/hw1/{number}", func(c *goweb.Context) { number, err := strconv.ParseInt(c.PathParams["number"], 10, 32) if err != nil { fmt.Fprintln(c.ResponseWriter, "Expecting valid number") } fmt.Fprintln(c.ResponseWriter, getHw1(int(number))) }) goweb.ListenAndServe("127.0.0.1:8080") }
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") }
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") }
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") }