diff --git a/.golangci.yml b/.golangci.yml
index c5e1de38..8ccd51ff 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -11,6 +11,7 @@ linters:
- exportloopref
- gci
- gofmt
+ - gofumpt
- goimports
- gosec
- misspell
diff --git a/binding/default_validator_test.go b/binding/default_validator_test.go
index ff130102..2d69aea9 100644
--- a/binding/default_validator_test.go
+++ b/binding/default_validator_test.go
@@ -18,14 +18,16 @@ func TestSliceValidationError(t *testing.T) {
{"has nil elements", SliceValidationError{errors.New("test error"), nil}, "[0]: test error"},
{"has zero elements", SliceValidationError{}, ""},
{"has one element", SliceValidationError{errors.New("test one error")}, "[0]: test one error"},
- {"has two elements",
+ {
+ "has two elements",
SliceValidationError{
errors.New("first error"),
errors.New("second error"),
},
"[0]: first error\n[1]: second error",
},
- {"has many elements",
+ {
+ "has many elements",
SliceValidationError{
errors.New("first error"),
errors.New("second error"),
diff --git a/binding/form.go b/binding/form.go
index fa2a6540..37435ea2 100644
--- a/binding/form.go
+++ b/binding/form.go
@@ -11,9 +11,11 @@ import (
const defaultMemory = 32 << 20
-type formBinding struct{}
-type formPostBinding struct{}
-type formMultipartBinding struct{}
+type (
+ formBinding struct{}
+ formPostBinding struct{}
+ formMultipartBinding struct{}
+)
func (formBinding) Name() string {
return "form"
diff --git a/binding/header.go b/binding/header.go
index b99302af..74e5e870 100644
--- a/binding/header.go
+++ b/binding/header.go
@@ -13,7 +13,6 @@ func (headerBinding) Name() string {
}
func (headerBinding) Bind(req *http.Request, obj interface{}) error {
-
if err := mapHeader(obj, req.Header); err != nil {
return err
}
diff --git a/binding/validate_test.go b/binding/validate_test.go
index 5299fbf6..924a62f4 100644
--- a/binding/validate_test.go
+++ b/binding/validate_test.go
@@ -157,16 +157,16 @@ type structNoValidationPointer struct {
}
func TestValidateNoValidationPointers(t *testing.T) {
- //origin := createNoValidation_values()
- //test := createNoValidation_values()
+ // origin := createNoValidation_values()
+ // test := createNoValidation_values()
empty := structNoValidationPointer{}
- //assert.Nil(t, validate(test))
- //assert.Nil(t, validate(&test))
+ // assert.Nil(t, validate(test))
+ // assert.Nil(t, validate(&test))
assert.Nil(t, validate(empty))
assert.Nil(t, validate(&empty))
- //assert.Equal(t, origin, test)
+ // assert.Equal(t, origin, test)
}
type Object map[string]interface{}
diff --git a/binding/xml.go b/binding/xml.go
index 4e901149..b04b18d8 100644
--- a/binding/xml.go
+++ b/binding/xml.go
@@ -24,6 +24,7 @@ func (xmlBinding) Bind(req *http.Request, obj interface{}) error {
func (xmlBinding) BindBody(body []byte, obj interface{}) error {
return decodeXML(bytes.NewReader(body), obj)
}
+
func decodeXML(r io.Reader, obj interface{}) error {
decoder := xml.NewDecoder(r)
if err := decoder.Decode(obj); err != nil {
diff --git a/ginS/gins.go b/ginS/gins.go
index ed054bfd..144cfd68 100644
--- a/ginS/gins.go
+++ b/ginS/gins.go
@@ -12,8 +12,10 @@ import (
"github.com/gin-gonic/gin"
)
-var once sync.Once
-var internalEngine *gin.Engine
+var (
+ once sync.Once
+ internalEngine *gin.Engine
+)
func engine() *gin.Engine {
once.Do(func() {
diff --git a/gin_integration_test.go b/gin_integration_test.go
index 8c22e7bd..59c7a3d4 100644
--- a/gin_integration_test.go
+++ b/gin_integration_test.go
@@ -26,7 +26,6 @@ import (
// params[1]=response status (custom compare status) default:"200 OK"
// params[2]=response body (custom compare content) default:"it worked"
func testRequest(t *testing.T, params ...string) {
-
if len(params) == 0 {
t.Fatal("url cannot be empty")
}
@@ -45,12 +44,12 @@ func testRequest(t *testing.T, params ...string) {
body, ioerr := ioutil.ReadAll(resp.Body)
assert.NoError(t, ioerr)
- var responseStatus = "200 OK"
+ responseStatus := "200 OK"
if len(params) > 1 && params[1] != "" {
responseStatus = params[1]
}
- var responseBody = "it worked"
+ responseBody := "it worked"
if len(params) > 2 && params[2] != "" {
responseBody = params[2]
}
@@ -168,7 +167,7 @@ func TestRunTLS(t *testing.T) {
}
func TestPusher(t *testing.T) {
- var html = template.Must(template.New("https").Parse(`
+ html := template.Must(template.New("https").Parse(`
Https Test
diff --git a/gin_test.go b/gin_test.go
index 21c43d15..a5f3aacc 100644
--- a/gin_test.go
+++ b/gin_test.go
@@ -43,7 +43,7 @@ func setupHTMLFiles(t *testing.T, mode string, tls bool, loadMethod func(*Engine
})
router.GET("/raw", func(c *Context) {
c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{
- "now": time.Date(2017, 07, 01, 0, 0, 0, 0, time.UTC),
+ "now": time.Date(2017, 0o7, 0o1, 0, 0, 0, 0, time.UTC),
})
})
})
@@ -395,7 +395,6 @@ func TestNoMethodWithoutGlobalHandlers(t *testing.T) {
}
func TestRebuild404Handlers(t *testing.T) {
-
}
func TestNoMethodWithGlobalHandlers(t *testing.T) {
@@ -636,7 +635,6 @@ func TestPrepareTrustedCIRDsWith(t *testing.T) {
assert.Nil(t, r.trustedCIDRs)
assert.Nil(t, err)
}
-
}
func parseCIDR(cidr string) *net.IPNet {
diff --git a/internal/bytesconv/bytesconv_test.go b/internal/bytesconv/bytesconv_test.go
index eeaad5ee..497069ce 100644
--- a/internal/bytesconv/bytesconv_test.go
+++ b/internal/bytesconv/bytesconv_test.go
@@ -12,8 +12,10 @@ import (
"time"
)
-var testString = "Albert Einstein: Logic will get you from A to B. Imagination will take you everywhere."
-var testBytes = []byte(testString)
+var (
+ testString = "Albert Einstein: Logic will get you from A to B. Imagination will take you everywhere."
+ testBytes = []byte(testString)
+)
func rawBytesToStr(b []byte) string {
return string(b)
diff --git a/logger_test.go b/logger_test.go
index 80961ce1..fce99504 100644
--- a/logger_test.go
+++ b/logger_test.go
@@ -228,7 +228,6 @@ func TestLoggerWithConfigFormatting(t *testing.T) {
assert.Equal(t, "/example?a=100", gotParam.Path)
assert.Empty(t, gotParam.ErrorMessage)
assert.Equal(t, gotKeys, gotParam.Keys)
-
}
func TestDefaultLogFormatter(t *testing.T) {
@@ -282,7 +281,6 @@ func TestDefaultLogFormatter(t *testing.T) {
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 5s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m \"/\"\n", defaultLogFormatter(termTrueParam))
assert.Equal(t, "[GIN] 2018/12/07 - 09:11:42 |\x1b[97;42m 200 \x1b[0m| 2743h29m3s | 20.20.20.20 |\x1b[97;44m GET \x1b[0m \"/\"\n", defaultLogFormatter(termTrueLongDurationParam))
-
}
func TestColorForMethod(t *testing.T) {
diff --git a/middleware_test.go b/middleware_test.go
index 4b4afd4a..5b9d8e0a 100644
--- a/middleware_test.go
+++ b/middleware_test.go
@@ -190,7 +190,6 @@ func TestMiddlewareAbortHandlersChainAndNext(t *testing.T) {
c.Next()
c.AbortWithStatus(http.StatusGone)
signature += "B"
-
})
router.GET("/", func(c *Context) {
signature += "C"
diff --git a/recovery_test.go b/recovery_test.go
index d164bfa3..3f716ebc 100644
--- a/recovery_test.go
+++ b/recovery_test.go
@@ -122,7 +122,6 @@ func TestPanicWithBrokenPipe(t *testing.T) {
for errno, expectMsg := range expectMsgs {
t.Run(expectMsg, func(t *testing.T) {
-
var buf bytes.Buffer
router := New()
diff --git a/render/html.go b/render/html.go
index 6696ece9..902604d6 100644
--- a/render/html.go
+++ b/render/html.go
@@ -63,6 +63,7 @@ func (r HTMLDebug) Instance(name string, data interface{}) Render {
Data: data,
}
}
+
func (r HTMLDebug) loadTemplate() *template.Template {
if r.FuncMap == nil {
r.FuncMap = template.FuncMap{}
diff --git a/routergroup.go b/routergroup.go
index 27d7aad6..0f06ef78 100644
--- a/routergroup.go
+++ b/routergroup.go
@@ -32,7 +32,6 @@ type IRouter interface {
// IRoutes defines all router handle interface.
type IRoutes interface {
Use(...HandlerFunc) IRoutes
-
Handle(string, string, ...HandlerFunc) IRoutes
Any(string, ...HandlerFunc) IRoutes
GET(string, ...HandlerFunc) IRoutes
@@ -42,7 +41,6 @@ type IRoutes interface {
PUT(string, ...HandlerFunc) IRoutes
OPTIONS(string, ...HandlerFunc) IRoutes
HEAD(string, ...HandlerFunc) IRoutes
-
StaticFile(string, string) IRoutes
Static(string, string) IRoutes
StaticFS(string, http.FileSystem) IRoutes
diff --git a/tree_test.go b/tree_test.go
index 94c53386..3dba2283 100644
--- a/tree_test.go
+++ b/tree_test.go
@@ -474,7 +474,7 @@ func TestTreeDuplicatePath(t *testing.T) {
}
}
- //printChildren(tree, "")
+ // printChildren(tree, "")
checkRequests(t, tree, testRequests{
{"/", false, "/", nil},
@@ -525,7 +525,7 @@ func TestTreeCatchAllConflictRoot(t *testing.T) {
func TestTreeCatchMaxParams(t *testing.T) {
tree := &node{}
- var route = "/cmd/*filepath"
+ route := "/cmd/*filepath"
tree.addRoute(route, fakeHandler(route))
}