Skip to content

url with trailing slash /hello/ match route "/hello/:name" should return 404 like net/http #4

@tablecell

Description

@tablecell
package main

import (
    "net/http"
    "github.com/cssivision/looli"
    "fmt"
)

func main() {
    router := looli.Default()  // new engine 
    
    router.SetTrailingSlashRedirect(false)
 
    router.Get("/hello/:name", func(c *looli.Context) {
         c.Status(200)
          link:=fmt.Sprintf("<a href='/' > %s </a> ",c.Param("name") )
          c.String(" goto "+link)
          c.String("hello " + c.Param("name") + "!\n")
    })

    http.ListenAndServe(":8080", router)
}


$ curl  http://localhost:8080/hello/
[looli] 2021/09/09 - 19:05:31 | 200 |    5.0003ms | 127.0.0.1 | GET  HTTP/1.1 /hello/

goto <a href='/' >  </a> hello !

as document

Named parameters only match a single path segment:

Pattern: /user/:name

 /user/gordon              match
 /user/you                 match
 /user/gordon/profile      no match
 /user/                    no match

/hello/  should return 404  like  net/http

package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/hello", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to my website!")
})
http.ListenAndServe(":8080", nil)
}

$ curl   http://localhost:8080/hello/
404 page not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions