go-restful
go-restful copied to clipboard
regex route path allows partial match
to accept case-insensitive paths, we use {h:(?i)hello}
, to accept /HELLO, /hello, /Hello.
but with this approach, it also triggered a bug where /xxxHello, /yyyHello also got accepted.
package main
import (
"io"
"log"
"net/http"
restful "github.com/emicklei/go-restful/v3"
)
func main() {
ws := new(restful.WebService)
ws.Route(ws.GET("/{h:(?i)hello}").To(hello))
restful.Add(ws)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func hello(req *restful.Request, resp *restful.Response) {
io.WriteString(resp, "world")
}