diff --git a/app.go b/app.go index fdcfda4a..7c10bc68 100644 --- a/app.go +++ b/app.go @@ -392,7 +392,7 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error { if !ok { port, ok := address.(int) if !ok { - return fmt.Errorf("Listen: Host must be an INT port or STRING address") + return fmt.Errorf("listen: host must be an `int` port or `string` address") } addr = strconv.Itoa(port) } @@ -437,7 +437,7 @@ func (app *App) Shutdown() error { app.mutex.Lock() defer app.mutex.Unlock() if app.server == nil { - return fmt.Errorf("Server is not running") + return fmt.Errorf("shutdown: server is not running") } return app.server.Shutdown() } @@ -477,7 +477,7 @@ func (app *App) Test(request *http.Request, msTimeout ...int) (*http.Response, e select { case err = <-channel: case <-time.After(time.Duration(timeout) * time.Millisecond): - return nil, fmt.Errorf("Timeout error %vms", timeout) + return nil, fmt.Errorf("test: timeout error %vms", timeout) } } else { // Without timeout diff --git a/app_test.go b/app_test.go index 935e7923..5457997b 100644 --- a/app_test.go +++ b/app_test.go @@ -43,7 +43,7 @@ func Test_App_ServerErrorHandler_SmallReadBuffer(t *testing.T) { app := New() app.Get("/", func(c *Ctx) { - panic(errors.New("Should never called")) + panic(errors.New("should never called")) }) request := httptest.NewRequest("GET", "/", nil) @@ -67,7 +67,7 @@ func Test_App_ErrorHandler(t *testing.T) { app := New() app.Get("/", func(c *Ctx) { - c.Next(errors.New("Hi, I'm an error!")) + c.Next(errors.New("hi, I'm an error")) }) resp, err := app.Test(httptest.NewRequest("GET", "/", nil)) @@ -76,7 +76,7 @@ func Test_App_ErrorHandler(t *testing.T) { body, err := ioutil.ReadAll(resp.Body) utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, "Hi, I'm an error!", string(body)) + utils.AssertEqual(t, "hi, I'm an error!", string(body)) } @@ -88,7 +88,7 @@ func Test_App_ErrorHandler_Custom(t *testing.T) { }) app.Get("/", func(c *Ctx) { - c.Next(errors.New("Hi, I'm an error!")) + c.Next(errors.New("hi, I'm an error")) }) resp, err := app.Test(httptest.NewRequest("GET", "/", nil)) @@ -97,7 +97,7 @@ func Test_App_ErrorHandler_Custom(t *testing.T) { body, err := ioutil.ReadAll(resp.Body) utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, "Hi, I'm an custom error!", string(body)) + utils.AssertEqual(t, "hi, I'm an custom error!", string(body)) } func Test_App_Nested_Params(t *testing.T) { diff --git a/ctx.go b/ctx.go index ea0fdf71..89917d3c 100644 --- a/ctx.go +++ b/ctx.go @@ -254,7 +254,7 @@ func (ctx *Ctx) BodyParser(out interface{}) error { return schemaDecoderQuery.Decode(out, data) } - return fmt.Errorf("BodyParser: cannot parse content-type: %v", ctype) + return fmt.Errorf("bodyparser: cannot parse content-type: %v", ctype) } // ClearCookie expires a specific cookie by key on the client side. @@ -687,7 +687,7 @@ func (ctx *Ctx) Query(key string) (value string) { func (ctx *Ctx) Range(size int) (rangeData Range, err error) { rangeStr := getString(ctx.Fasthttp.Request.Header.Peek(HeaderRange)) if rangeStr == "" || !strings.Contains(rangeStr, "=") { - return rangeData, fmt.Errorf("malformed range header string") + return rangeData, fmt.Errorf("range: malformed range header string") } data := strings.Split(rangeStr, "=") rangeData.Type = data[0] @@ -695,7 +695,7 @@ func (ctx *Ctx) Range(size int) (rangeData Range, err error) { for i := 0; i < len(arr); i++ { item := strings.Split(arr[i], "-") if len(item) == 1 { - return rangeData, fmt.Errorf("malformed range header string") + return rangeData, fmt.Errorf("range: malformed range header string") } start, startErr := strconv.Atoi(item[0]) end, endErr := strconv.Atoi(item[1]) @@ -720,7 +720,7 @@ func (ctx *Ctx) Range(size int) (rangeData Range, err error) { }) } if len(rangeData.Ranges) < 1 { - return rangeData, fmt.Errorf("unsatisfiable range") + return rangeData, fmt.Errorf("range: unsatisfiable range") } return rangeData, nil } @@ -865,7 +865,7 @@ func (ctx *Ctx) SendFile(file string, compress ...bool) error { sendFileHandler(ctx.Fasthttp) // Check for error if status != 404 && ctx.Fasthttp.Response.StatusCode() == 404 { - return fmt.Errorf("file %s not found", file) + return fmt.Errorf("sendfile: file %s not found", file) } // Restore status code ctx.Fasthttp.Response.SetStatusCode(status) diff --git a/ctx_test.go b/ctx_test.go index 1c777598..d2451fc1 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -568,7 +568,7 @@ func Benchmark_Ctx_Is(b *testing.B) { b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { - res = c.Is(".json") + _ = c.Is(".json") res = c.Is("json") } utils.AssertEqual(b, true, res) @@ -679,9 +679,9 @@ func Benchmark_Ctx_Params(b *testing.B) { b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { - res = c.Params("param1") - res = c.Params("param2") - res = c.Params("param3") + _ = c.Params("param1") + _ = c.Params("param2") + _ = c.Params("param3") res = c.Params("param4") } utils.AssertEqual(b, "awesome", res) diff --git a/middleware/compress.go b/middleware/compress.go index 6ce0f0c1..88036405 100644 --- a/middleware/compress.go +++ b/middleware/compress.go @@ -24,7 +24,7 @@ const ( CompressLevelBestCompression = 2 ) -// Default config +// CompressConfigDefault is the default config var CompressConfigDefault = CompressConfig{ Next: nil, Level: CompressLevelDefault, diff --git a/middleware/logger.go b/middleware/logger.go index 510b41ff..19f3cf15 100644 --- a/middleware/logger.go +++ b/middleware/logger.go @@ -86,7 +86,7 @@ const ( LoggerTagCookie = "cookie:" ) -// Default config +// LoggerConfigDefault is the default config var LoggerConfigDefault = LoggerConfig{ Next: nil, Format: "${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n", @@ -115,7 +115,7 @@ func LoggerWithConfig(config LoggerConfig) fiber.Handler { tmpl.new(config.Format, "${", "}") timestamp := time.Now().Format(config.TimeFormat) - // Update date/time every second in a seperate go routine + // Update date/time every second in a separate go routine if strings.Contains(config.Format, "${time}") { go func() { for { @@ -261,7 +261,7 @@ func (t *loggerTemplate) new(template, startTag, endTag string) { s = s[n+len(a):] n = bytes.Index(s, b) if n < 0 { - panic(fmt.Errorf("Cannot find end tag=%q in the template=%q starting from %q", endTag, template, s)) + panic(fmt.Errorf("cannot find end tag=%q in the template=%q starting from %q", endTag, template, s)) } t.tags = append(t.tags, utils.GetString(s[:n])) diff --git a/middleware/recover.go b/middleware/recover.go index 52389631..b15a365d 100644 --- a/middleware/recover.go +++ b/middleware/recover.go @@ -15,7 +15,7 @@ type ( } ) -// RecoverConfigDefault config +// RecoverConfigDefault is the default config var RecoverConfigDefault = RecoverConfig{ Next: nil, } diff --git a/middleware/request_id.go b/middleware/request_id.go index 70fbaf35..9ad83006 100644 --- a/middleware/request_id.go +++ b/middleware/request_id.go @@ -24,7 +24,7 @@ type ( } ) -// Default config +// RequestIDConfigDefault is the default config var RequestIDConfigDefault = RequestIDConfig{ Next: nil, Header: fiber.HeaderXRequestID, @@ -45,7 +45,7 @@ func RequestID(header ...string) fiber.Handler { return RequestIDWithConfig(config) } -// RequestID adds an UUID indentifier to the request +// RequestIDWithConfig allows you to pass a custom config func RequestIDWithConfig(config RequestIDConfig) fiber.Handler { // Set default values if config.Header == "" { diff --git a/router_test.go b/router_test.go index 7295c640..8ee11ff1 100644 --- a/router_test.go +++ b/router_test.go @@ -16,7 +16,7 @@ import ( fasthttp "github.com/valyala/fasthttp" ) -var routesFixture = routeJson{} +var routesFixture = routeJSON{} func init() { dat, err := ioutil.ReadFile("./.github/fixture/testRoutes.json") @@ -418,7 +418,7 @@ type testRoute struct { Method string `json:"method"` Path string `json:"path"` } -type routeJson struct { +type routeJSON struct { TestRoutes []testRoute `json:"testRoutes"` GithubAPI []testRoute `json:"githubAPI"` } diff --git a/utils_test.go b/utils_test.go index 6bcb48bf..d604acea 100644 --- a/utils_test.go +++ b/utils_test.go @@ -235,9 +235,9 @@ func Test_Utils_matchParams(t *testing.T) { func Benchmark_Utils_getGroupPath(b *testing.B) { var res string for n := 0; n < b.N; n++ { - res = getGroupPath("/v1/long/path/john/doe", "/why/this/name/is/so/awesome") - res = getGroupPath("/v1", "/") - res = getGroupPath("/v1", "/api") + _ = getGroupPath("/v1/long/path/john/doe", "/why/this/name/is/so/awesome") + _ = getGroupPath("/v1", "/") + _ = getGroupPath("/v1", "/api") res = getGroupPath("/v1", "/api/register/:project") } utils.AssertEqual(b, "/v1/api/register/:project", res)