package main
import (
"fmt"
"github.com/gocraft/web"
"net/http"
)
type Context struct {
HelloCount int
}
func (c *Context) Test(rw web.ResponseWriter, req *web.Request) {
fmt.Println(c)
fmt.Fprint(rw, req.PathParams["uid"])
}
func main() {
router := web.New(Context{}).
Get("/test/:uid", (*Context).Test)
http.ListenAndServe("localhost:3000", router)
}
curl http://localhost:3000/test/web
curl http://localhost:3000/test/web/
all return 200
int standart net/http
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/test/web", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to my website!")
})
http.ListenAndServe(":8080", nil)
}
curl http://localhost:3000/test/web return 200
curl http://localhost:3000/test/web/ return 404