diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b7e0dc8..ae62885 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -24,7 +24,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v7 with: version: latest args: --timeout=30m diff --git a/.golangci.yml b/.golangci.yml index 82dd9ef..6937629 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,19 +1,31 @@ -linters-settings: - nakedret: - max-func-lines: 0 # Disallow any unnamed return statement - +version: "2" linters: enable: - - unused - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - typecheck - nakedret - - gofmt - rowserrcheck - unconvert - - goimports - unparam + settings: + nakedret: + max-func-lines: 0 # Disallow any unnamed return statement + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/go.mod b/go.mod index 417dcf5..9a25739 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/go-macaron/inject v0.0.0-20160627170012-d8a0b8677191 github.com/smartystreets/goconvey v1.8.1 github.com/unknwon/com v0.0.0-20190804042917-757f69c95f3e - golang.org/x/crypto v0.36.0 + golang.org/x/crypto v0.37.0 gopkg.in/ini.v1 v1.66.6 ) diff --git a/go.sum b/go.sum index e5f572a..b5872c0 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/unknwon/com v0.0.0-20190804042917-757f69c95f3e h1:GSGeB9EAKY2spCABz6xOX5DbxZEXolK+nBSvmsQwRjM= github.com/unknwon/com v0.0.0-20190804042917-757f69c95f3e/go.mod h1:tOOxU81rwgoCLoOVVPHb6T/wt8HZygqH5id+GNnlCXM= -golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= -golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= +golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI= gopkg.in/ini.v1 v1.66.6/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/macaron.go b/macaron.go index 17c92f5..f36bb8e 100644 --- a/macaron.go +++ b/macaron.go @@ -125,7 +125,7 @@ func NewWithLogger(out io.Writer) *Macaron { Router: NewRouter(), logger: log.New(out, "[Macaron] ", 0), } - m.Router.m = m + m.m = m m.Map(m.logger) m.Map(defaultReturnHandler()) m.NotFound(http.NotFound) diff --git a/recovery.go b/recovery.go index 25e46ee..27a1e21 100644 --- a/recovery.go +++ b/recovery.go @@ -127,7 +127,7 @@ func function(pc uintptr) []byte { if period := bytes.Index(name, dot); period >= 0 { name = name[period+1:] } - name = bytes.Replace(name, centerDot, dot, -1) + name = bytes.ReplaceAll(name, centerDot, dot) return name } diff --git a/render.go b/render.go index f32f2d2..dd03c31 100644 --- a/render.go +++ b/render.go @@ -281,7 +281,7 @@ func compile(opt RenderOptions) *template.Template { opt.TemplateFileSystem = NewTemplateFileSystem(opt, false) } - for _, f := range opt.TemplateFileSystem.ListFiles() { + for _, f := range opt.ListFiles() { tmpl := t.New(f.Name()) for _, funcs := range opt.Funcs { tmpl.Funcs(funcs) @@ -533,11 +533,11 @@ func (r *TplRender) addYield(t *template.Template, tplName string, data interfac } func (r *TplRender) renderBytes(setName, tplName string, data interface{}, htmlOpt ...HTMLOptions) (*bytes.Buffer, error) { - t := r.TemplateSet.Get(setName) + t := r.Get(setName) if Env == DEV { opt := *r.Opt - opt.Directory = r.TemplateSet.GetDir(setName) - t = r.TemplateSet.Set(setName, &opt) + opt.Directory = r.GetDir(setName) + t = r.Set(setName, &opt) } if t == nil { return nil, fmt.Errorf("html/template: template \"%s\" is undefined", tplName) @@ -634,11 +634,11 @@ func (r *TplRender) SetTemplatePath(setName, dir string) { } opt := *r.Opt opt.Directory = dir - r.TemplateSet.Set(setName, &opt) + r.Set(setName, &opt) } func (r *TplRender) HasTemplateSet(name string) bool { - return r.TemplateSet.Get(name) != nil + return r.Get(name) != nil } // DummyRender is used when user does not choose any real render to use. diff --git a/render_test.go b/render_test.go index fa46cab..3049684 100644 --- a/render_test.go +++ b/render_test.go @@ -686,19 +686,19 @@ func Test_dummyRender(t *testing.T) { }) m.Get("/htmlsetstring", func(ctx *Context) { defer shouldPanic() - _, _ = ctx.Render.HTMLSetString("", "", nil) + _, _ = ctx.HTMLSetString("", "", nil) }) m.Get("/htmlstring", func(ctx *Context) { defer shouldPanic() - _, _ = ctx.Render.HTMLString("", nil) + _, _ = ctx.HTMLString("", nil) }) m.Get("/htmlsetbytes", func(ctx *Context) { defer shouldPanic() - _, _ = ctx.Render.HTMLSetBytes("", "", nil) + _, _ = ctx.HTMLSetBytes("", "", nil) }) m.Get("/htmlbytes", func(ctx *Context) { defer shouldPanic() - _, _ = ctx.Render.HTMLBytes("", nil) + _, _ = ctx.HTMLBytes("", nil) }) m.Get("/xml", func(ctx *Context) { defer shouldPanic() diff --git a/router_test.go b/router_test.go index 3e38b98..7ca6c01 100644 --- a/router_test.go +++ b/router_test.go @@ -46,7 +46,7 @@ func test_Router_Handle(t *testing.T, isFast bool) { if isFast { // FastInvoker Handler Wrap Action - m.Router.SetHandlerWrapper(func(h Handler) Handler { + m.SetHandlerWrapper(func(h Handler) Handler { switch v := h.(type) { case func() string: return handlerFunc0Invoker(v) @@ -138,7 +138,7 @@ func test_Router_Handle(t *testing.T, isFast bool) { if isFast { //remove Handler Wrap Action - m.Router.SetHandlerWrapper(nil) + m.SetHandlerWrapper(nil) } }) diff --git a/static_test.go b/static_test.go index b0af11c..79643bf 100644 --- a/static_test.go +++ b/static_test.go @@ -77,7 +77,7 @@ func Test_Static(t *testing.T) { resp := httptest.NewRecorder() resp.Body = new(bytes.Buffer) - req, err := http.NewRequest("GET", "http://localhost:4000/"+path.Base(strings.Replace(f.Name(), "\\", "/", -1)), nil) + req, err := http.NewRequest("GET", "http://localhost:4000/"+path.Base(strings.ReplaceAll(f.Name(), "\\", "/")), nil) So(err, ShouldBeNil) m.ServeHTTP(resp, req) So(resp.Code, ShouldEqual, http.StatusOK) diff --git a/tree.go b/tree.go index 1143e34..fc2aa13 100644 --- a/tree.go +++ b/tree.go @@ -97,8 +97,8 @@ func getWildcards(pattern string) (string, []string) { // getRawPattern removes all regexp but keeps wildcards for building URL path. func getRawPattern(rawPattern string) string { - rawPattern = strings.Replace(rawPattern, ":int", "", -1) - rawPattern = strings.Replace(rawPattern, ":string", "", -1) + rawPattern = strings.ReplaceAll(rawPattern, ":int", "") + rawPattern = strings.ReplaceAll(rawPattern, ":string", "") for { startIdx := strings.Index(rawPattern, "(") @@ -136,10 +136,7 @@ func checkPattern(pattern string) (typ patternType, rawPattern string, wildcards func NewLeaf(parent *Tree, pattern string, handle Handle) *Leaf { typ, rawPattern, wildcards, reg := checkPattern(pattern) - optional := false - if len(pattern) > 0 && pattern[0] == '?' { - optional = true - } + optional := len(pattern) > 0 && pattern[0] == '?' return &Leaf{parent, typ, pattern, rawPattern, wildcards, reg, optional, handle} } @@ -348,7 +345,8 @@ func (t *Tree) matchSubtree(globLevel int, segment, url string, params Params) ( if err != nil { return nil, false } - if leaf.typ == _PATTERN_PATH_EXT { + switch leaf.typ { + case _PATTERN_PATH_EXT: j := strings.LastIndex(unescapedURL, ".") if j > -1 { params[":path"] = unescapedURL[:j] @@ -357,7 +355,7 @@ func (t *Tree) matchSubtree(globLevel int, segment, url string, params Params) ( params[":path"] = unescapedURL } return leaf.handle, true - } else if leaf.typ == _PATTERN_MATCH_ALL { + case _PATTERN_MATCH_ALL: params["*"] = unescapedURL params["*"+com.ToStr(globLevel)] = unescapedURL return leaf.handle, true