goreportcard fix

pull/457/head
Fenny 2020-06-08 02:55:19 +02:00
parent bffd8b06b1
commit fbea5211d0
10 changed files with 29 additions and 29 deletions

6
app.go
View File

@ -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

View File

@ -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) {

10
ctx.go
View File

@ -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)

View File

@ -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)

View File

@ -24,7 +24,7 @@ const (
CompressLevelBestCompression = 2
)
// Default config
// CompressConfigDefault is the default config
var CompressConfigDefault = CompressConfig{
Next: nil,
Level: CompressLevelDefault,

View File

@ -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]))

View File

@ -15,7 +15,7 @@ type (
}
)
// RecoverConfigDefault config
// RecoverConfigDefault is the default config
var RecoverConfigDefault = RecoverConfig{
Next: nil,
}

View File

@ -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 == "" {

View File

@ -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"`
}

View File

@ -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)