diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..d59c99b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,39 @@ +linters: + enable-all: false + disable-all: true + fast: false + enable: + - bodyclose + - dogsled + - dupl + - errcheck + - exportloopref + - exhaustive + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - noctx + - nolintlint + - rowserrcheck + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - whitespace + - gofumpt + +run: + timeout: 3m diff --git a/dynamic.go b/dynamic.go index 0642d50..a272c70 100644 --- a/dynamic.go +++ b/dynamic.go @@ -129,7 +129,11 @@ func (r DynamicRender) AddFromString(name, templateString string) *template.Temp } // AddFromStringsFuncs supply add template from strings -func (r DynamicRender) AddFromStringsFuncs(name string, funcMap template.FuncMap, templateStrings ...string) *template.Template { +func (r DynamicRender) AddFromStringsFuncs( + name string, + funcMap template.FuncMap, + templateStrings ...string, +) *template.Template { builder := &templateBuilder{ templateName: name, funcMap: funcMap, templateStrings: templateStrings, diff --git a/dynamic_test.go b/dynamic_test.go index 0a2cefa..ef001ca 100644 --- a/dynamic_test.go +++ b/dynamic_test.go @@ -39,7 +39,11 @@ func createFromStringDynamic() Renderer { func createFromStringsWithFuncsDynamic() Renderer { r := NewRenderer() - r.AddFromStringsFuncs("index", template.FuncMap{}, `Welcome to {{ .name }} {{template "content"}}`, `{{define "content"}}template{{end}}`) + r.AddFromStringsFuncs( + "index", + template.FuncMap{}, + `Welcome to {{ .name }} {{template "content"}}`, `{{define "content"}}template{{end}}`, + ) return r } @@ -79,7 +83,7 @@ func TestAddFromFilesDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) } @@ -93,7 +97,7 @@ func TestAddFromGlobDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is login template\n", w.Body.String()) } @@ -107,7 +111,7 @@ func TestAddFromFSDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) } @@ -121,7 +125,7 @@ func TestAddFromStringDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template", w.Body.String()) } @@ -135,7 +139,7 @@ func TestAddFromStringsFruncsDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template", w.Body.String()) } @@ -149,7 +153,7 @@ func TestAddFromFilesFruncsDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template\n", w.Body.String()) } diff --git a/example/advanced/example.go b/example/advanced/example.go index 9465850..0467537 100644 --- a/example/advanced/example.go +++ b/example/advanced/example.go @@ -44,8 +44,8 @@ func loadTemplates(templatesDir string) multitemplate.Renderer { for _, include := range includes { layoutCopy := make([]string, len(layouts)) copy(layoutCopy, layouts) - files := append(layoutCopy, include) - r.AddFromFiles(filepath.Base(include), files...) + layoutCopy = append(layoutCopy, include) + r.AddFromFiles(filepath.Base(include), layoutCopy...) } return r } diff --git a/example/multibase/example.go b/example/multibase/example.go index 2a5d743..f2df977 100644 --- a/example/multibase/example.go +++ b/example/multibase/example.go @@ -44,8 +44,8 @@ func loadTemplates(templatesDir string) multitemplate.Renderer { for _, article := range articles { layoutCopy := make([]string, len(articleLayouts)) copy(layoutCopy, articleLayouts) - files := append(layoutCopy, article) - r.AddFromFiles(filepath.Base(article), files...) + layoutCopy = append(layoutCopy, article) + r.AddFromFiles(filepath.Base(article), layoutCopy...) } adminLayouts, err := filepath.Glob(templatesDir + "/layouts/admin-base.html") @@ -62,8 +62,8 @@ func loadTemplates(templatesDir string) multitemplate.Renderer { for _, admin := range admins { layoutCopy := make([]string, len(adminLayouts)) copy(layoutCopy, adminLayouts) - files := append(layoutCopy, admin) - r.AddFromFiles(filepath.Base(admin), files...) + layoutCopy = append(layoutCopy, admin) + r.AddFromFiles(filepath.Base(admin), layoutCopy...) } return r } diff --git a/multitemplate.go b/multitemplate.go index 09c2978..94937b6 100644 --- a/multitemplate.go +++ b/multitemplate.go @@ -65,7 +65,11 @@ func (r Render) AddFromString(name, templateString string) *template.Template { } // AddFromStringsFuncs supply add template from strings -func (r Render) AddFromStringsFuncs(name string, funcMap template.FuncMap, templateStrings ...string) *template.Template { +func (r Render) AddFromStringsFuncs( + name string, + funcMap template.FuncMap, + templateStrings ...string, +) *template.Template { tmpl := template.New(name).Funcs(funcMap) for _, ts := range templateStrings { diff --git a/multitemplate_test.go b/multitemplate_test.go index 6b631de..f0d2854 100644 --- a/multitemplate_test.go +++ b/multitemplate_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/assert" ) -func performRequest(r http.Handler, method, path string) *httptest.ResponseRecorder { - req, _ := http.NewRequestWithContext(context.Background(), method, path, nil) +func performRequest(r http.Handler) *httptest.ResponseRecorder { + req, _ := http.NewRequestWithContext(context.Background(), "GET", "/", nil) w := httptest.NewRecorder() r.ServeHTTP(w, req) return w @@ -49,7 +49,11 @@ func createFromString() Render { func createFromStringsWithFuncs() Render { r := New() - r.AddFromStringsFuncs("index", template.FuncMap{}, `Welcome to {{ .name }} {{template "content"}}`, `{{define "content"}}template{{end}}`) + r.AddFromStringsFuncs( + "index", + template.FuncMap{}, + `Welcome to {{ .name }} {{template "content"}}`, `{{define "content"}}template{{end}}`, + ) return r } @@ -82,7 +86,7 @@ func TestAddFromFiles(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) } @@ -96,7 +100,7 @@ func TestAddFromGlob(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is login template\n", w.Body.String()) } @@ -110,7 +114,7 @@ func TestAddFromFS(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) } @@ -124,7 +128,7 @@ func TestAddFromString(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template", w.Body.String()) } @@ -138,7 +142,7 @@ func TestAddFromStringsFruncs(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template", w.Body.String()) } @@ -152,7 +156,7 @@ func TestAddFromFilesFruncs(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template\n", w.Body.String()) }