From b8228e4546d535c8ee37f7c94658f58d6e61bb42 Mon Sep 17 00:00:00 2001 From: Fenny <25108519+Fenny@users.noreply.github.com> Date: Tue, 12 May 2020 23:24:04 +0200 Subject: [PATCH] Golint code --- app.go | 6 ++---- ctx_bench_test.go | 11 ++++++----- router.go | 6 +++--- utils.go | 6 +++--- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app.go b/app.go index d08147b7..40d52a37 100644 --- a/app.go +++ b/app.go @@ -120,7 +120,7 @@ func New(settings ...*Settings) *App { // Create app app := new(App) // Create route stack - app.routes = make([][]*Route, len(methodINT), len(methodINT)) + app.routes = make([][]*Route, len(methodINT)) // Create settings app.Settings = new(Settings) // Set default settings @@ -456,9 +456,7 @@ func (app *App) Test(request *http.Request, msTimeout ...int) (*http.Response, e } } else { // Without timeout - select { - case err = <-channel: - } + err = <-channel } // Check for errors if err != nil { diff --git a/ctx_bench_test.go b/ctx_bench_test.go index 72414b58..9e7b07cd 100644 --- a/ctx_bench_test.go +++ b/ctx_bench_test.go @@ -334,11 +334,11 @@ func Benchmark_Ctx_JSON(b *testing.B) { Name: "Grame", Age: 20, } - + var err error 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())) } @@ -355,11 +355,12 @@ func Benchmark_Ctx_JSONP(b *testing.B) { Name: "Grame", Age: 20, } - + var err error 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())) } diff --git a/router.go b/router.go index 41e43891..df8889c8 100644 --- a/router.go +++ b/router.go @@ -62,18 +62,18 @@ func (app *App) nextRoute(ctx *Ctx) { func (r *Route) matchRoute(path string) (match bool, values []string) { if r.use { - if r.root == true || strings.HasPrefix(path, r.Path) { + if r.root || strings.HasPrefix(path, r.Path) { return true, values } // Check for a simple path match } else if len(r.Path) == len(path) && r.Path == path { return true, values // Middleware routes allow prefix matches - } else if r.root == true && path == "/" { + } else if r.root && path == "/" { return true, values } // '*' wildcard matches any path - if r.star == true { + if r.star { return true, []string{path} } // Does this route have parameters diff --git a/utils.go b/utils.go index 4a33b776..84954e37 100644 --- a/utils.go +++ b/utils.go @@ -732,7 +732,7 @@ type paramSeg struct { IsLast bool } -var paramsDummy = make([]string, 100, 100) +var paramsDummy = make([]string, 100) const wildcardParam string = "*" @@ -763,7 +763,7 @@ func getParams(pattern string) (p parsedParams) { params = append(params, out[segIndex].Param) } else { // combine const segments - if segIndex > 0 && out[segIndex-1].IsParam == false { + if segIndex > 0 && !out[segIndex-1].IsParam { segIndex-- out[segIndex].Const += "/" + aPattern[i] // create new const segment @@ -812,7 +812,7 @@ func (p *parsedParams) getMatch(s string, partialCheck bool) ([]string, bool) { i = partLen } - if false == segment.IsOptional && i == 0 { + if !segment.IsOptional && i == 0 { return nil, false }