enable gofumpt linter

This commit is contained in:
Matthieu MOREL 2021-12-28 19:54:37 +01:00 committed by GitHub
parent 47111e2d4e
commit c9b28e5920
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 31 additions and 30 deletions

View File

@ -11,6 +11,7 @@ linters:
- exportloopref - exportloopref
- gci - gci
- gofmt - gofmt
- gofumpt
- goimports - goimports
- gosec - gosec
- misspell - misspell

View File

@ -18,14 +18,16 @@ func TestSliceValidationError(t *testing.T) {
{"has nil elements", SliceValidationError{errors.New("test error"), nil}, "[0]: test error"}, {"has nil elements", SliceValidationError{errors.New("test error"), nil}, "[0]: test error"},
{"has zero elements", SliceValidationError{}, ""}, {"has zero elements", SliceValidationError{}, ""},
{"has one element", SliceValidationError{errors.New("test one error")}, "[0]: test one error"}, {"has one element", SliceValidationError{errors.New("test one error")}, "[0]: test one error"},
{"has two elements", {
"has two elements",
SliceValidationError{ SliceValidationError{
errors.New("first error"), errors.New("first error"),
errors.New("second error"), errors.New("second error"),
}, },
"[0]: first error\n[1]: second error", "[0]: first error\n[1]: second error",
}, },
{"has many elements", {
"has many elements",
SliceValidationError{ SliceValidationError{
errors.New("first error"), errors.New("first error"),
errors.New("second error"), errors.New("second error"),

View File

@ -11,9 +11,11 @@ import (
const defaultMemory = 32 << 20 const defaultMemory = 32 << 20
type formBinding struct{} type (
type formPostBinding struct{} formBinding struct{}
type formMultipartBinding struct{} formPostBinding struct{}
formMultipartBinding struct{}
)
func (formBinding) Name() string { func (formBinding) Name() string {
return "form" return "form"

View File

@ -13,7 +13,6 @@ func (headerBinding) Name() string {
} }
func (headerBinding) Bind(req *http.Request, obj interface{}) error { func (headerBinding) Bind(req *http.Request, obj interface{}) error {
if err := mapHeader(obj, req.Header); err != nil { if err := mapHeader(obj, req.Header); err != nil {
return err return err
} }

View File

@ -157,16 +157,16 @@ type structNoValidationPointer struct {
} }
func TestValidateNoValidationPointers(t *testing.T) { func TestValidateNoValidationPointers(t *testing.T) {
//origin := createNoValidation_values() // origin := createNoValidation_values()
//test := createNoValidation_values() // test := createNoValidation_values()
empty := structNoValidationPointer{} 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.Nil(t, validate(&empty)) assert.Nil(t, validate(&empty))
//assert.Equal(t, origin, test) // assert.Equal(t, origin, test)
} }
type Object map[string]interface{} type Object map[string]interface{}

View File

@ -24,6 +24,7 @@ func (xmlBinding) Bind(req *http.Request, obj interface{}) error {
func (xmlBinding) BindBody(body []byte, obj interface{}) error { func (xmlBinding) BindBody(body []byte, obj interface{}) error {
return decodeXML(bytes.NewReader(body), obj) return decodeXML(bytes.NewReader(body), obj)
} }
func decodeXML(r io.Reader, obj interface{}) error { func decodeXML(r io.Reader, obj interface{}) error {
decoder := xml.NewDecoder(r) decoder := xml.NewDecoder(r)
if err := decoder.Decode(obj); err != nil { if err := decoder.Decode(obj); err != nil {

View File

@ -12,8 +12,10 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
var once sync.Once var (
var internalEngine *gin.Engine once sync.Once
internalEngine *gin.Engine
)
func engine() *gin.Engine { func engine() *gin.Engine {
once.Do(func() { once.Do(func() {

View File

@ -26,7 +26,6 @@ import (
// params[1]=response status (custom compare status) default:"200 OK" // params[1]=response status (custom compare status) default:"200 OK"
// params[2]=response body (custom compare content) default:"it worked" // params[2]=response body (custom compare content) default:"it worked"
func testRequest(t *testing.T, params ...string) { func testRequest(t *testing.T, params ...string) {
if len(params) == 0 { if len(params) == 0 {
t.Fatal("url cannot be empty") t.Fatal("url cannot be empty")
} }
@ -45,12 +44,12 @@ func testRequest(t *testing.T, params ...string) {
body, ioerr := ioutil.ReadAll(resp.Body) body, ioerr := ioutil.ReadAll(resp.Body)
assert.NoError(t, ioerr) assert.NoError(t, ioerr)
var responseStatus = "200 OK" responseStatus := "200 OK"
if len(params) > 1 && params[1] != "" { if len(params) > 1 && params[1] != "" {
responseStatus = params[1] responseStatus = params[1]
} }
var responseBody = "it worked" responseBody := "it worked"
if len(params) > 2 && params[2] != "" { if len(params) > 2 && params[2] != "" {
responseBody = params[2] responseBody = params[2]
} }
@ -168,7 +167,7 @@ func TestRunTLS(t *testing.T) {
} }
func TestPusher(t *testing.T) { func TestPusher(t *testing.T) {
var html = template.Must(template.New("https").Parse(` html := template.Must(template.New("https").Parse(`
<html> <html>
<head> <head>
<title>Https Test</title> <title>Https Test</title>

View File

@ -43,7 +43,7 @@ func setupHTMLFiles(t *testing.T, mode string, tls bool, loadMethod func(*Engine
}) })
router.GET("/raw", func(c *Context) { router.GET("/raw", func(c *Context) {
c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{ 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 TestRebuild404Handlers(t *testing.T) {
} }
func TestNoMethodWithGlobalHandlers(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, r.trustedCIDRs)
assert.Nil(t, err) assert.Nil(t, err)
} }
} }
func parseCIDR(cidr string) *net.IPNet { func parseCIDR(cidr string) *net.IPNet {

View File

@ -12,8 +12,10 @@ import (
"time" "time"
) )
var testString = "Albert Einstein: Logic will get you from A to B. Imagination will take you everywhere." var (
var testBytes = []byte(testString) testString = "Albert Einstein: Logic will get you from A to B. Imagination will take you everywhere."
testBytes = []byte(testString)
)
func rawBytesToStr(b []byte) string { func rawBytesToStr(b []byte) string {
return string(b) return string(b)

View File

@ -228,7 +228,6 @@ func TestLoggerWithConfigFormatting(t *testing.T) {
assert.Equal(t, "/example?a=100", gotParam.Path) assert.Equal(t, "/example?a=100", gotParam.Path)
assert.Empty(t, gotParam.ErrorMessage) assert.Empty(t, gotParam.ErrorMessage)
assert.Equal(t, gotKeys, gotParam.Keys) assert.Equal(t, gotKeys, gotParam.Keys)
} }
func TestDefaultLogFormatter(t *testing.T) { 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| 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)) 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) { func TestColorForMethod(t *testing.T) {

View File

@ -190,7 +190,6 @@ func TestMiddlewareAbortHandlersChainAndNext(t *testing.T) {
c.Next() c.Next()
c.AbortWithStatus(http.StatusGone) c.AbortWithStatus(http.StatusGone)
signature += "B" signature += "B"
}) })
router.GET("/", func(c *Context) { router.GET("/", func(c *Context) {
signature += "C" signature += "C"

View File

@ -122,7 +122,6 @@ func TestPanicWithBrokenPipe(t *testing.T) {
for errno, expectMsg := range expectMsgs { for errno, expectMsg := range expectMsgs {
t.Run(expectMsg, func(t *testing.T) { t.Run(expectMsg, func(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
router := New() router := New()

View File

@ -63,6 +63,7 @@ func (r HTMLDebug) Instance(name string, data interface{}) Render {
Data: data, Data: data,
} }
} }
func (r HTMLDebug) loadTemplate() *template.Template { func (r HTMLDebug) loadTemplate() *template.Template {
if r.FuncMap == nil { if r.FuncMap == nil {
r.FuncMap = template.FuncMap{} r.FuncMap = template.FuncMap{}

View File

@ -32,7 +32,6 @@ type IRouter interface {
// IRoutes defines all router handle interface. // IRoutes defines all router handle interface.
type IRoutes interface { type IRoutes interface {
Use(...HandlerFunc) IRoutes Use(...HandlerFunc) IRoutes
Handle(string, string, ...HandlerFunc) IRoutes Handle(string, string, ...HandlerFunc) IRoutes
Any(string, ...HandlerFunc) IRoutes Any(string, ...HandlerFunc) IRoutes
GET(string, ...HandlerFunc) IRoutes GET(string, ...HandlerFunc) IRoutes
@ -42,7 +41,6 @@ type IRoutes interface {
PUT(string, ...HandlerFunc) IRoutes PUT(string, ...HandlerFunc) IRoutes
OPTIONS(string, ...HandlerFunc) IRoutes OPTIONS(string, ...HandlerFunc) IRoutes
HEAD(string, ...HandlerFunc) IRoutes HEAD(string, ...HandlerFunc) IRoutes
StaticFile(string, string) IRoutes StaticFile(string, string) IRoutes
Static(string, string) IRoutes Static(string, string) IRoutes
StaticFS(string, http.FileSystem) IRoutes StaticFS(string, http.FileSystem) IRoutes

View File

@ -474,7 +474,7 @@ func TestTreeDuplicatePath(t *testing.T) {
} }
} }
//printChildren(tree, "") // printChildren(tree, "")
checkRequests(t, tree, testRequests{ checkRequests(t, tree, testRequests{
{"/", false, "/", nil}, {"/", false, "/", nil},
@ -525,7 +525,7 @@ func TestTreeCatchAllConflictRoot(t *testing.T) {
func TestTreeCatchMaxParams(t *testing.T) { func TestTreeCatchMaxParams(t *testing.T) {
tree := &node{} tree := &node{}
var route = "/cmd/*filepath" route := "/cmd/*filepath"
tree.addRoute(route, fakeHandler(route)) tree.addRoute(route, fakeHandler(route))
} }