From 53db5562b4fb8da9b7a7be694233ff7bcff0b35b Mon Sep 17 00:00:00 2001 From: golangboy Date: Sat, 24 Feb 2024 13:22:22 +0800 Subject: [PATCH] fix: golangci-lint errors --- event/listener/template_config.go | 2 +- model/dto/base.go | 2 +- template/extension/link.go | 2 -- template/extension/tool.go | 2 -- util/file.go | 8 ++++---- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/event/listener/template_config.go b/event/listener/template_config.go index e0aaf7e2..e37267a1 100644 --- a/event/listener/template_config.go +++ b/event/listener/template_config.go @@ -119,7 +119,7 @@ func (t *TemplateConfigListener) loadThemeConfig(ctx context.Context) error { if err != nil { return err } - themeBasePath := "" + var themeBasePath string if isEnabledAbsolutePath { themeBasePath = blogBaseURL + "/themes/" + theme.FolderName } else { diff --git a/model/dto/base.go b/model/dto/base.go index 7b72b15a..29228097 100644 --- a/model/dto/base.go +++ b/model/dto/base.go @@ -29,7 +29,7 @@ type Page struct { } func NewPage(content interface{}, totalCount int64, page param.Page) *Page { - contentLen := 0 + var contentLen int r := reflect.ValueOf(content) if !r.IsNil() && r.Kind() != reflect.Slice { diff --git a/template/extension/link.go b/template/extension/link.go index db814450..f523d15f 100644 --- a/template/extension/link.go +++ b/template/extension/link.go @@ -3,7 +3,6 @@ package extension import ( "context" "math/rand" - "time" "github.com/go-sonic/sonic/model/dto" "github.com/go-sonic/sonic/service" @@ -45,7 +44,6 @@ func (l *linkExtension) addListLinksRandom() { if err != nil { return nil, err } - rand.Seed(time.Now().UnixNano()) rand.Shuffle(len(links), func(i, j int) { links[i], links[j] = links[j], links[i] }) diff --git a/template/extension/tool.go b/template/extension/tool.go index 3fe06980..b4221451 100644 --- a/template/extension/tool.go +++ b/template/extension/tool.go @@ -2,7 +2,6 @@ package extension import ( "math/rand" - "time" "github.com/go-sonic/sonic/template" "github.com/go-sonic/sonic/util" @@ -26,7 +25,6 @@ func (t *toolExtension) addRainbow() { } func (t *toolExtension) addRandom() { - rand.Seed(time.Now().UnixNano()) random := func(min, max int) int { return min + rand.Intn(max-min) } diff --git a/util/file.go b/util/file.go index 634b42e3..12fd6338 100644 --- a/util/file.go +++ b/util/file.go @@ -40,7 +40,7 @@ func ZipFile(dst string, srcs ...string) (err error) { // 通过文件信息,创建 zip 的文件信息 fh, err := zip.FileInfoHeader(fi) if err != nil { - return + return err } if path == src { fh.Name = filepath.Base(src) @@ -58,7 +58,7 @@ func ZipFile(dst string, srcs ...string) (err error) { // 写入文件信息,并返回一个 Write 结构 w, err := zw.CreateHeader(fh) if err != nil { - return + return err } // 检测,如果不是标准文件就只写入头信息,不写入文件数据到 w @@ -70,14 +70,14 @@ func ZipFile(dst string, srcs ...string) (err error) { // 打开要压缩的文件 fr, err := os.Open(path) if err != nil { - return + return err } defer fr.Close() // 将打开的文件 Copy 到 w _, err = io.Copy(w, fr) if err != nil { - return + return err } // 输出压缩的内容