Unmarshalling body params with json.Unmarshal supports case-insensitive
matching against struct tags. Matching query params case insensitive
provides a more sane and consistent experience for API consumers.
The original url.Values keys remain case sensitive.
Old error message
`
Unmarshal type error: expected=int, got=string, offset=47
`
New error message
`
Unmarshal type error: expected=int, got=string, field=age, offset=47
`
Make it easy to fix for client.
This is a follow-up to #1101. It turns out that that patch is
incomplete, as a similar check also needs to be added in the
`Router.Add()` method.
I don't understand why the test works fine, but when using it in a real
application. For example with this example:
func main() {
e := echo.New()
e.GET("/xxx/:id.json", func(c echo.Context) error {
return c.String(200, fmt.Sprintf("%#v: names: %#v; vals: %#v",
c.Path(), c.ParamNames(), c.ParamValues()))
})
log.Fatal(e.Start(":8000"))
}
Gives a 404 on `/xxx/42.json`, and for `/xxx/42` it gives the output:
/xxx/:id.json": names: []string{"id.json"}; vals: []string{"42"}
It makes sense to add the test there too; I just don't get why the test
cases that I added in ##1101 *does* produce the correct output :-/
Currently a route in the form of `/foo/:id.json` means echo will detect
the parameter name `id.json` instead of the expected `id`. I think this
is rather counter-intuitive, as adding an extension to paths is a fairly
common use case.
With this change both a `/` and a `.` will be treated as the end of a
parameter name.
Benchmark before this change:
$ go test -bench .
[..]
goos: linux
goarch: amd64
pkg: github.com/labstack/echo
BenchmarkRouterStaticRoutes-4 100000 17743 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGitHubAPI-4 50000 33081 ns/op 1 B/op 0 allocs/op
BenchmarkRouterParseAPI-4 300000 5370 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGooglePlusAPI-4 200000 9183 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/labstack/echo 8.565s
After this change:
goos: linux
goarch: amd64
pkg: github.com/labstack/echo
BenchmarkRouterStaticRoutes-4 100000 17699 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGitHubAPI-4 50000 32962 ns/op 1 B/op 0 allocs/op
BenchmarkRouterParseAPI-4 300000 5450 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGooglePlusAPI-4 200000 9205 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/labstack/echo 8.590s
Fixes#599