Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 25 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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$
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
})

Expand Down
2 changes: 1 addition & 1 deletion static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "(")
Expand Down Expand Up @@ -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}
}

Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
Loading