Skip to content

url with trailing slash match route Get("/test/:uid" should be 404  #92

@tablecell

Description

@tablecell
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions