mirror of https://github.com/gofiber/fiber.git
Golint code
parent
6e0595ee25
commit
b8228e4546
6
app.go
6
app.go
|
@ -120,7 +120,7 @@ func New(settings ...*Settings) *App {
|
||||||
// Create app
|
// Create app
|
||||||
app := new(App)
|
app := new(App)
|
||||||
// Create route stack
|
// Create route stack
|
||||||
app.routes = make([][]*Route, len(methodINT), len(methodINT))
|
app.routes = make([][]*Route, len(methodINT))
|
||||||
// Create settings
|
// Create settings
|
||||||
app.Settings = new(Settings)
|
app.Settings = new(Settings)
|
||||||
// Set default settings
|
// Set default settings
|
||||||
|
@ -456,9 +456,7 @@ func (app *App) Test(request *http.Request, msTimeout ...int) (*http.Response, e
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Without timeout
|
// Without timeout
|
||||||
select {
|
err = <-channel
|
||||||
case err = <-channel:
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -334,11 +334,11 @@ func Benchmark_Ctx_JSON(b *testing.B) {
|
||||||
Name: "Grame",
|
Name: "Grame",
|
||||||
Age: 20,
|
Age: 20,
|
||||||
}
|
}
|
||||||
|
var err error
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
c.JSON(data)
|
err = c.JSON(data)
|
||||||
}
|
}
|
||||||
|
assertEqual(b, nil, err)
|
||||||
assertEqual(b, `{"Name":"Grame","Age":20}`, string(c.Fasthttp.Response.Body()))
|
assertEqual(b, `{"Name":"Grame","Age":20}`, string(c.Fasthttp.Response.Body()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,11 +355,12 @@ func Benchmark_Ctx_JSONP(b *testing.B) {
|
||||||
Name: "Grame",
|
Name: "Grame",
|
||||||
Age: 20,
|
Age: 20,
|
||||||
}
|
}
|
||||||
|
var err error
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
c.JSONP(data, "john")
|
err = c.JSONP(data, "john")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertEqual(b, nil, err)
|
||||||
assertEqual(b, `john({"Name":"Grame","Age":20});`, string(c.Fasthttp.Response.Body()))
|
assertEqual(b, `john({"Name":"Grame","Age":20});`, string(c.Fasthttp.Response.Body()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,18 +62,18 @@ func (app *App) nextRoute(ctx *Ctx) {
|
||||||
|
|
||||||
func (r *Route) matchRoute(path string) (match bool, values []string) {
|
func (r *Route) matchRoute(path string) (match bool, values []string) {
|
||||||
if r.use {
|
if r.use {
|
||||||
if r.root == true || strings.HasPrefix(path, r.Path) {
|
if r.root || strings.HasPrefix(path, r.Path) {
|
||||||
return true, values
|
return true, values
|
||||||
}
|
}
|
||||||
// Check for a simple path match
|
// Check for a simple path match
|
||||||
} else if len(r.Path) == len(path) && r.Path == path {
|
} else if len(r.Path) == len(path) && r.Path == path {
|
||||||
return true, values
|
return true, values
|
||||||
// Middleware routes allow prefix matches
|
// Middleware routes allow prefix matches
|
||||||
} else if r.root == true && path == "/" {
|
} else if r.root && path == "/" {
|
||||||
return true, values
|
return true, values
|
||||||
}
|
}
|
||||||
// '*' wildcard matches any path
|
// '*' wildcard matches any path
|
||||||
if r.star == true {
|
if r.star {
|
||||||
return true, []string{path}
|
return true, []string{path}
|
||||||
}
|
}
|
||||||
// Does this route have parameters
|
// Does this route have parameters
|
||||||
|
|
6
utils.go
6
utils.go
|
@ -732,7 +732,7 @@ type paramSeg struct {
|
||||||
IsLast bool
|
IsLast bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var paramsDummy = make([]string, 100, 100)
|
var paramsDummy = make([]string, 100)
|
||||||
|
|
||||||
const wildcardParam string = "*"
|
const wildcardParam string = "*"
|
||||||
|
|
||||||
|
@ -763,7 +763,7 @@ func getParams(pattern string) (p parsedParams) {
|
||||||
params = append(params, out[segIndex].Param)
|
params = append(params, out[segIndex].Param)
|
||||||
} else {
|
} else {
|
||||||
// combine const segments
|
// combine const segments
|
||||||
if segIndex > 0 && out[segIndex-1].IsParam == false {
|
if segIndex > 0 && !out[segIndex-1].IsParam {
|
||||||
segIndex--
|
segIndex--
|
||||||
out[segIndex].Const += "/" + aPattern[i]
|
out[segIndex].Const += "/" + aPattern[i]
|
||||||
// create new const segment
|
// create new const segment
|
||||||
|
@ -812,7 +812,7 @@ func (p *parsedParams) getMatch(s string, partialCheck bool) ([]string, bool) {
|
||||||
i = partLen
|
i = partLen
|
||||||
}
|
}
|
||||||
|
|
||||||
if false == segment.IsOptional && i == 0 {
|
if !segment.IsOptional && i == 0 {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue