Route example in readme gives error: errors.go:54: Unsupported HTTP request method provided.
Closed this issue · 1 comments
masoudd commented
Hello. This code in the readme:
import (
"github.com/bnkamalesh/webgo"
"github.com/bnkamalesh/webgo/middleware"
)
func routes() []*webgo.Route {
return []*webgo.Route{
&webo.Route{
Name: "home",
Pattern: "/",
Handlers: []http.HandlerFunc{
func(w http.ResponseWriter, r *http.Request) {
webgo.R200(w, "home")
}
},
},
}
}
func main() {
router := webgo.NewRouter(*webgo.Config, routes())
router.UseOnSpecialHandlers(middleware.AccessLog)
router.Use(middleware.AccessLog)
router.Start()
}
Doesn't work. You need to define a Method field in the Route struct. Also it complains about *webgo.Config not being an expression (unless it was intentional as a placeholder for any pointer to Config). This works:
func routes() []*webgo.Route {
return []*webgo.Route{
&webo.Route{
Name: "home",
Method: "GET",
Pattern: "/",
Handlers: []http.HandlerFunc{
func(w http.ResponseWriter, r *http.Request) {
webgo.R200(w, "home")
}
},
},
}
}
func main() {
config := webgo.Config{
Host: "localhost",
Port: "8888",
}
router := webgo.NewRouter(&config, routes())
router.UseOnSpecialHandlers(middleware.AccessLog)
router.Use(middleware.AccessLog)
router.Start()
}
bnkamalesh commented
Hey @masoudd , thank you for highlighting these issues. I've pushed changes to fix it.