mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-19 15:57:48 +08:00
Merge branch 'master' into render-tc-1
This commit is contained in:
commit
11ab2c49de
@ -10,7 +10,6 @@ matrix:
|
|||||||
env: GO111MODULE=on
|
env: GO111MODULE=on
|
||||||
- go: 1.13.x
|
- go: 1.13.x
|
||||||
- go: master
|
- go: master
|
||||||
env: GO111MODULE=on
|
|
||||||
|
|
||||||
git:
|
git:
|
||||||
depth: 10
|
depth: 10
|
||||||
|
13
README.md
13
README.md
@ -1678,11 +1678,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return server01.ListenAndServe()
|
err := server01.ListenAndServe()
|
||||||
|
if err != nil && err != http.ErrServerClosed {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return server02.ListenAndServe()
|
err := server02.ListenAndServe()
|
||||||
|
if err != nil && err != http.ErrServerClosed {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := g.Wait(); err != nil {
|
if err := g.Wait(); err != nil {
|
||||||
@ -1799,6 +1807,7 @@ func main() {
|
|||||||
func loadTemplate() (*template.Template, error) {
|
func loadTemplate() (*template.Template, error) {
|
||||||
t := template.New("")
|
t := template.New("")
|
||||||
for name, file := range Assets.Files {
|
for name, file := range Assets.Files {
|
||||||
|
defer file.Close()
|
||||||
if file.IsDir() || !strings.HasSuffix(name, ".tmpl") {
|
if file.IsDir() || !strings.HasSuffix(name, ".tmpl") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -393,8 +393,7 @@ func (c *Context) QueryArray(key string) []string {
|
|||||||
|
|
||||||
func (c *Context) getQueryCache() {
|
func (c *Context) getQueryCache() {
|
||||||
if c.queryCache == nil {
|
if c.queryCache == nil {
|
||||||
c.queryCache = make(url.Values)
|
c.queryCache = c.Request.URL.Query()
|
||||||
c.queryCache, _ = url.ParseQuery(c.Request.URL.RawQuery)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,14 @@ func TestSetMode(t *testing.T) {
|
|||||||
assert.Panics(t, func() { SetMode("unknown") })
|
assert.Panics(t, func() { SetMode("unknown") })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDisableBindValidation(t *testing.T) {
|
||||||
|
v := binding.Validator
|
||||||
|
assert.NotNil(t, binding.Validator)
|
||||||
|
DisableBindValidation()
|
||||||
|
assert.Nil(t, binding.Validator)
|
||||||
|
binding.Validator = v
|
||||||
|
}
|
||||||
|
|
||||||
func TestEnableJsonDecoderUseNumber(t *testing.T) {
|
func TestEnableJsonDecoderUseNumber(t *testing.T) {
|
||||||
assert.False(t, binding.EnableDecoderUseNumber)
|
assert.False(t, binding.EnableDecoderUseNumber)
|
||||||
EnableJsonDecoderUseNumber()
|
EnableJsonDecoderUseNumber()
|
||||||
|
@ -388,7 +388,17 @@ func TestRenderRedirect(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w = httptest.NewRecorder()
|
w = httptest.NewRecorder()
|
||||||
assert.Panics(t, func() { assert.NoError(t, data2.Render(w)) })
|
assert.PanicsWithValue(t, "Cannot redirect with status code 200", func() { data2.Render(w) })
|
||||||
|
|
||||||
|
data3 := Redirect{
|
||||||
|
Code: http.StatusCreated,
|
||||||
|
Request: req,
|
||||||
|
Location: "/new/location",
|
||||||
|
}
|
||||||
|
|
||||||
|
w = httptest.NewRecorder()
|
||||||
|
err = data3.Render(w)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// only improve coverage
|
// only improve coverage
|
||||||
data2.WriteContentType(w)
|
data2.WriteContentType(w)
|
||||||
|
5
tree.go
5
tree.go
@ -65,10 +65,9 @@ func min(a, b int) int {
|
|||||||
func countParams(path string) uint8 {
|
func countParams(path string) uint8 {
|
||||||
var n uint
|
var n uint
|
||||||
for i := 0; i < len(path); i++ {
|
for i := 0; i < len(path); i++ {
|
||||||
if path[i] != ':' && path[i] != '*' {
|
if path[i] == ':' || path[i] == '*' {
|
||||||
continue
|
n++
|
||||||
}
|
}
|
||||||
n++
|
|
||||||
}
|
}
|
||||||
if n >= 255 {
|
if n >= 255 {
|
||||||
return 255
|
return 255
|
||||||
|
Loading…
x
Reference in New Issue
Block a user