From 61f15955228c48f2ca0761a900b28859ffa7e819 Mon Sep 17 00:00:00 2001 From: ferhat elmas Date: Fri, 28 Nov 2025 23:11:57 +0100 Subject: [PATCH] feat: add golangci-lint into lint target * replace empty interface with any * run fmt via golangci-lint related to #1432 Signed-off-by: ferhat elmas --- .gitignore | 2 +- .golangci.yaml | 30 +++++++++++++++++++ Makefile | 17 +++++++++-- docs/docs.go | 7 ++--- docs/swagger.json | 7 ++--- docs/swagger.yaml | 6 ++-- internal/base/handler/handler.go | 6 ++-- internal/base/handler/response.go | 4 +-- internal/base/pager/pager.go | 2 +- internal/base/pager/pagination.go | 6 ++-- internal/base/server/http_funcmap.go | 6 ++-- internal/base/translator/provider.go | 8 ++--- internal/base/validator/validator.go | 4 +-- internal/install/install_from_env.go | 2 +- internal/migrations/init.go | 10 +++---- internal/migrations/init_data.go | 2 +- internal/migrations/v25.go | 2 +- internal/migrations/v6.go | 2 +- internal/repo/meta/meta_repo.go | 2 +- .../plugin_config/plugin_user_config_repo.go | 2 +- internal/repo/revision/revision_repo.go | 2 +- internal/repo/role/user_role_rel_repo.go | 2 +- internal/repo/search_common/search_repo.go | 26 ++++++++-------- internal/repo/user/user_repo.go | 2 +- internal/schema/question_schema.go | 28 ++++++++--------- internal/schema/revision_schema.go | 2 +- internal/schema/siteinfo_schema.go | 14 ++++----- internal/schema/user_schema.go | 2 +- internal/service/question_common/question.go | 2 +- internal/service/siteinfo/siteinfo_service.go | 2 +- .../siteinfo_common/siteinfo_service.go | 4 +-- pkg/converter/str.go | 2 +- 32 files changed, 125 insertions(+), 90 deletions(-) create mode 100644 .golangci.yaml diff --git a/.gitignore b/.gitignore index 1fc116a74..257ef31d6 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,7 @@ vendor/ /answer-data/ /answer /new_answer - +build/tools/ dist/ # Lint setup generated file diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 000000000..af00efc3b --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +version: "2" +linters: + default: none + +formatters: + enable: + - gofmt + settings: + gofmt: + simplify: true + rewrite-rules: + - pattern: 'interface{}' + replacement: 'any' diff --git a/Makefile b/Makefile index 8ab23cce3..fd3f044fa 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,15 @@ Revision=$(shell git rev-parse --short HEAD 2>/dev/null || echo "") GO_FLAGS=-ldflags="-X github.com/apache/answer/cmd.Version=$(VERSION) -X 'github.com/apache/answer/cmd.Revision=$(Revision)' -X 'github.com/apache/answer/cmd.Time=`date +%s`' -extldflags -static" GO=$(GO_ENV) "$(shell which go)" +GOLANGCI_VERSION ?= v2.6.2 +TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools) + +GOLANGCI = $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION) +$(GOLANGCI): + rm -f $(TOOLS_BIN)/golangci-lint* + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_VERSION)/install.sh | sh -s -- -b $(TOOLS_BIN) $(GOLANGCI_VERSION) + mv $(TOOLS_BIN)/golangci-lint $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION) + build: generate @$(GO) build $(GO_FLAGS) -o $(BIN) $(DIR_SRC) @@ -50,8 +59,12 @@ install-ui-packages: ui: @cd ui && pnpm pre-install && pnpm build && cd - -lint: generate +lint: generate $(GOLANGCI) + @bash ./script/check-asf-header.sh + $(GOLANGCI) run + +lint-fix: generate $(GOLANGCI) @bash ./script/check-asf-header.sh - @gofmt -w -l . + $(GOLANGCI) run --fix all: clean build diff --git a/docs/docs.go b/docs/docs.go index c87313917..5e9d5b39d 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -8080,9 +8080,6 @@ const docTemplate = `{ "id": { "type": "string" }, - "question_id": { - "type": "string" - }, "title": { "type": "string" } @@ -10920,7 +10917,7 @@ const docTemplate = `{ }, "theme_config": { "type": "object", - "additionalProperties": true + "additionalProperties": {} } } }, @@ -10935,7 +10932,7 @@ const docTemplate = `{ }, "theme_config": { "type": "object", - "additionalProperties": true + "additionalProperties": {} }, "theme_options": { "type": "array", diff --git a/docs/swagger.json b/docs/swagger.json index 9f89cb157..e0f6378e4 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -8053,9 +8053,6 @@ "id": { "type": "string" }, - "question_id": { - "type": "string" - }, "title": { "type": "string" } @@ -10893,7 +10890,7 @@ }, "theme_config": { "type": "object", - "additionalProperties": true + "additionalProperties": {} } } }, @@ -10908,7 +10905,7 @@ }, "theme_config": { "type": "object", - "additionalProperties": true + "additionalProperties": {} }, "theme_options": { "type": "array", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index d2dd076cf..e0244083b 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -399,8 +399,6 @@ definitions: type: string id: type: string - question_id: - type: string title: type: string required: @@ -2364,7 +2362,7 @@ definitions: maxLength: 255 type: string theme_config: - additionalProperties: true + additionalProperties: {} type: object required: - theme @@ -2376,7 +2374,7 @@ definitions: theme: type: string theme_config: - additionalProperties: true + additionalProperties: {} type: object theme_options: items: diff --git a/internal/base/handler/handler.go b/internal/base/handler/handler.go index 7670feea7..5a4961a3e 100644 --- a/internal/base/handler/handler.go +++ b/internal/base/handler/handler.go @@ -31,7 +31,7 @@ import ( ) // HandleResponse Handle response body -func HandleResponse(ctx *gin.Context, err error, data interface{}) { +func HandleResponse(ctx *gin.Context, err error, data any) { lang := GetLang(ctx) // no error if err == nil { @@ -61,7 +61,7 @@ func HandleResponse(ctx *gin.Context, err error, data interface{}) { } // BindAndCheck bind request and check -func BindAndCheck(ctx *gin.Context, data interface{}) bool { +func BindAndCheck(ctx *gin.Context, data any) bool { lang := GetLang(ctx) ctx.Set(constant.AcceptLanguageFlag, lang) if err := ctx.ShouldBind(data); err != nil { @@ -79,7 +79,7 @@ func BindAndCheck(ctx *gin.Context, data interface{}) bool { } // BindAndCheckReturnErr bind request and check -func BindAndCheckReturnErr(ctx *gin.Context, data interface{}) (errFields []*validator.FormErrorField) { +func BindAndCheckReturnErr(ctx *gin.Context, data any) (errFields []*validator.FormErrorField) { lang := GetLang(ctx) if err := ctx.ShouldBind(data); err != nil { log.Errorf("http_handle BindAndCheck fail, %s", err.Error()) diff --git a/internal/base/handler/response.go b/internal/base/handler/response.go index 827e0b362..51be8a8a1 100644 --- a/internal/base/handler/response.go +++ b/internal/base/handler/response.go @@ -34,7 +34,7 @@ type RespBody struct { // response message Message string `json:"msg"` // response data - Data interface{} `json:"data"` + Data any `json:"data"` } // TrMsg translate the reason cause as a message @@ -63,7 +63,7 @@ func NewRespBodyFromError(e *errors.Error) *RespBody { } // NewRespBodyData new response body with data -func NewRespBodyData(code int, reason string, data interface{}) *RespBody { +func NewRespBodyData(code int, reason string, data any) *RespBody { return &RespBody{ Code: code, Reason: reason, diff --git a/internal/base/pager/pager.go b/internal/base/pager/pager.go index d7a4caa14..b14d99bfa 100644 --- a/internal/base/pager/pager.go +++ b/internal/base/pager/pager.go @@ -27,7 +27,7 @@ import ( ) // Help xorm page helper -func Help(page, pageSize int, rowsSlicePtr interface{}, rowElement interface{}, session *xorm.Session) (total int64, err error) { +func Help(page, pageSize int, rowsSlicePtr any, rowElement any, session *xorm.Session) (total int64, err error) { page, pageSize = ValPageAndPageSize(page, pageSize) sliceValue := reflect.Indirect(reflect.ValueOf(rowsSlicePtr)) diff --git a/internal/base/pager/pagination.go b/internal/base/pager/pagination.go index 36849fed5..1b09e1f21 100644 --- a/internal/base/pager/pagination.go +++ b/internal/base/pager/pagination.go @@ -25,8 +25,8 @@ import ( // PageModel page model type PageModel struct { - Count int64 `json:"count"` - List interface{} `json:"list"` + Count int64 `json:"count"` + List any `json:"list"` } // PageCond page condition @@ -36,7 +36,7 @@ type PageCond struct { } // NewPageModel new page model -func NewPageModel(totalRecords int64, records interface{}) *PageModel { +func NewPageModel(totalRecords int64, records any) *PageModel { sliceValue := reflect.Indirect(reflect.ValueOf(records)) if sliceValue.Kind() != reflect.Slice { panic("not a slice") diff --git a/internal/base/server/http_funcmap.go b/internal/base/server/http_funcmap.go index 9d8e98f96..8f6cac5fc 100644 --- a/internal/base/server/http_funcmap.go +++ b/internal/base/server/http_funcmap.go @@ -64,7 +64,7 @@ var funcMap = template.FuncMap{ "formatLinkNofollow": func(data string) template.HTML { return template.HTML(FormatLinkNofollow(data)) }, - "translator": func(la i18n.Language, data string, params ...interface{}) string { + "translator": func(la i18n.Language, data string, params ...any) string { trans := translator.GlobalTrans.Tr(la, data) if len(params) > 0 && len(params)%2 == 0 { @@ -128,8 +128,8 @@ var funcMap = template.FuncMap{ trans = translator.GlobalTrans.Tr(la, "ui.dates.long_date_with_year") return day.Format(timestamp, trans, tz) }, - "wrapComments": func(comments []*schema.GetCommentResp, la i18n.Language, tz string) map[string]interface{} { - return map[string]interface{}{ + "wrapComments": func(comments []*schema.GetCommentResp, la i18n.Language, tz string) map[string]any { + return map[string]any{ "comments": comments, "language": la, "timezone": tz, diff --git a/internal/base/translator/provider.go b/internal/base/translator/provider.go index 9838d185d..47212e84f 100644 --- a/internal/base/translator/provider.go +++ b/internal/base/translator/provider.go @@ -76,14 +76,14 @@ func NewTranslator(c *I18n) (tr i18n.Translator, err error) { // parse the backend translation originalTr := struct { - Backend map[string]map[string]interface{} `yaml:"backend"` - UI map[string]interface{} `yaml:"ui"` - Plugin map[string]interface{} `yaml:"plugin"` + Backend map[string]map[string]any `yaml:"backend"` + UI map[string]any `yaml:"ui"` + Plugin map[string]any `yaml:"plugin"` }{} if err = yaml.Unmarshal(buf, &originalTr); err != nil { return nil, err } - translation := make(map[string]interface{}, 0) + translation := make(map[string]any, 0) for k, v := range originalTr.Backend { translation[k] = v } diff --git a/internal/base/validator/validator.go b/internal/base/validator/validator.go index 70c7be2e9..22761c521 100644 --- a/internal/base/validator/validator.go +++ b/internal/base/validator/validator.go @@ -187,7 +187,7 @@ func GetValidatorByLang(lang i18n.Language) *MyValidator { } // Check / -func (m *MyValidator) Check(value interface{}) (errFields []*FormErrorField, err error) { +func (m *MyValidator) Check(value any) (errFields []*FormErrorField, err error) { defer func() { if len(errFields) == 0 { return @@ -261,7 +261,7 @@ type Checker interface { Check() (errField []*FormErrorField, err error) } -func getObjectTagByFieldName(obj interface{}, fieldName string) (tag string) { +func getObjectTagByFieldName(obj any, fieldName string) (tag string) { defer func() { if err := recover(); err != nil { log.Error(err) diff --git a/internal/install/install_from_env.go b/internal/install/install_from_env.go index a6b668bab..c05d2aaba 100644 --- a/internal/install/install_from_env.go +++ b/internal/install/install_from_env.go @@ -133,7 +133,7 @@ func initBaseInfo(env *Env) (err error) { return requestAPI(req, "POST", "/installation/base-info", InitBaseInfo) } -func requestAPI(req interface{}, method, url string, handlerFunc gin.HandlerFunc) error { +func requestAPI(req any, method, url string, handlerFunc gin.HandlerFunc) error { w := httptest.NewRecorder() c, _ := gin.CreateTestContext(w) body, _ := json.Marshal(req) diff --git a/internal/migrations/init.go b/internal/migrations/init.go index 392ecb2c6..184c986b9 100644 --- a/internal/migrations/init.go +++ b/internal/migrations/init.go @@ -208,7 +208,7 @@ func (m *Mentor) initSiteInfoGeneralData() { } func (m *Mentor) initSiteInfoLoginConfig() { - loginConfig := map[string]interface{}{ + loginConfig := map[string]any{ "allow_new_registrations": true, "allow_email_registrations": true, "allow_password_login": true, @@ -223,7 +223,7 @@ func (m *Mentor) initSiteInfoLoginConfig() { } func (m *Mentor) initSiteInfoLegalConfig() { - legalConfig := map[string]interface{}{ + legalConfig := map[string]any{ "external_content_display": m.userData.ExternalContentDisplay, } legalConfigDataBytes, _ := json.Marshal(legalConfig) @@ -244,7 +244,7 @@ func (m *Mentor) initSiteInfoThemeConfig() { } func (m *Mentor) initSiteInfoSEOConfig() { - seoData := map[string]interface{}{ + seoData := map[string]any{ "permalink": constant.PermalinkQuestionID, "robots": defaultSEORobotTxt + m.userData.SiteURL + "/sitemap.xml", } @@ -276,7 +276,7 @@ func (m *Mentor) initSiteInfoUsersConfig() { } func (m *Mentor) initSiteInfoPrivilegeRank() { - privilegeRankData := map[string]interface{}{ + privilegeRankData := map[string]any{ "level": schema.PrivilegeLevel2, } privilegeRankDataBytes, _ := json.Marshal(privilegeRankData) @@ -288,7 +288,7 @@ func (m *Mentor) initSiteInfoPrivilegeRank() { } func (m *Mentor) initSiteInfoWrite() { - writeData := map[string]interface{}{ + writeData := map[string]any{ "min_content": 6, "restrict_answer": true, "min_tags": 1, diff --git a/internal/migrations/init_data.go b/internal/migrations/init_data.go index 96151625d..356a915a7 100644 --- a/internal/migrations/init_data.go +++ b/internal/migrations/init_data.go @@ -43,7 +43,7 @@ Sitemap: ` ) var ( - tables = []interface{}{ + tables = []any{ &entity.Activity{}, &entity.Answer{}, &entity.Collection{}, diff --git a/internal/migrations/v25.go b/internal/migrations/v25.go index 560a852ac..228c2ef26 100644 --- a/internal/migrations/v25.go +++ b/internal/migrations/v25.go @@ -39,7 +39,7 @@ func addFileRecord(ctx context.Context, x *xorm.Engine) error { if err != nil { return fmt.Errorf("get legal config failed: %w", err) } - legalConfig := make(map[string]interface{}) + legalConfig := make(map[string]any) if exist { if err := json.Unmarshal([]byte(legalInfo.Content), &legalConfig); err != nil { return fmt.Errorf("unmarshal legal config failed: %w", err) diff --git a/internal/migrations/v6.go b/internal/migrations/v6.go index 9171ad47a..88fb58497 100644 --- a/internal/migrations/v6.go +++ b/internal/migrations/v6.go @@ -45,7 +45,7 @@ func addNewAnswerNotification(ctx context.Context, x *xorm.Engine) error { } } - m := make(map[string]interface{}) + m := make(map[string]any) _ = json.Unmarshal([]byte(cond.Value), &m) m["new_answer_title"] = "[{{.SiteName}}] {{.DisplayName}} answered your question" m["new_answer_body"] = "{{.QuestionTitle}}

\n\n{{.DisplayName}}:
\n
{{.AnswerSummary}}

\nView it on {{.SiteName}}

\n\nYou are receiving this because you authored the thread. Unsubscribe" diff --git a/internal/repo/meta/meta_repo.go b/internal/repo/meta/meta_repo.go index 767bd04c7..9680fb419 100644 --- a/internal/repo/meta/meta_repo.go +++ b/internal/repo/meta/meta_repo.go @@ -72,7 +72,7 @@ func (mr *metaRepo) UpdateMeta(ctx context.Context, meta *entity.Meta) (err erro // AddOrUpdateMetaByObjectIdAndKey if exist record with same objectID and key, update it. Or create a new one func (mr *metaRepo) AddOrUpdateMetaByObjectIdAndKey(ctx context.Context, objectId, key string, f func(*entity.Meta, bool) (*entity.Meta, error)) error { - _, err := mr.data.DB.Transaction(func(session *xorm.Session) (interface{}, error) { + _, err := mr.data.DB.Transaction(func(session *xorm.Session) (any, error) { session = session.Context(ctx) // 1. acquire meta entity with target object id and key diff --git a/internal/repo/plugin_config/plugin_user_config_repo.go b/internal/repo/plugin_config/plugin_user_config_repo.go index 19d6af5f9..83da8e758 100644 --- a/internal/repo/plugin_config/plugin_user_config_repo.go +++ b/internal/repo/plugin_config/plugin_user_config_repo.go @@ -44,7 +44,7 @@ func NewPluginUserConfigRepo(data *data.Data) plugin_common.PluginUserConfigRepo func (ur *pluginUserConfigRepo) SaveUserPluginConfig(ctx context.Context, userID string, pluginSlugName, configValue string) (err error) { - _, err = ur.data.DB.Transaction(func(session *xorm.Session) (interface{}, error) { + _, err = ur.data.DB.Transaction(func(session *xorm.Session) (any, error) { session = session.Context(ctx) old := &entity.PluginUserConfig{ UserID: userID, diff --git a/internal/repo/revision/revision_repo.go b/internal/repo/revision/revision_repo.go index 09ba1aacd..8b9e08400 100644 --- a/internal/repo/revision/revision_repo.go +++ b/internal/repo/revision/revision_repo.go @@ -64,7 +64,7 @@ func (rr *revisionRepo) AddRevision(ctx context.Context, revision *entity.Revisi if !rr.allowRecord(revision.ObjectType) { return nil } - _, err = rr.data.DB.Transaction(func(session *xorm.Session) (interface{}, error) { + _, err = rr.data.DB.Transaction(func(session *xorm.Session) (any, error) { session = session.Context(ctx) _, err = session.Insert(revision) if err != nil { diff --git a/internal/repo/role/user_role_rel_repo.go b/internal/repo/role/user_role_rel_repo.go index 7bd14ecea..1925339c0 100644 --- a/internal/repo/role/user_role_rel_repo.go +++ b/internal/repo/role/user_role_rel_repo.go @@ -45,7 +45,7 @@ func NewUserRoleRelRepo(data *data.Data) role.UserRoleRelRepo { // SaveUserRoleRel save user role rel func (ur *userRoleRelRepo) SaveUserRoleRel(ctx context.Context, userID string, roleID int) (err error) { - _, err = ur.data.DB.Transaction(func(session *xorm.Session) (interface{}, error) { + _, err = ur.data.DB.Transaction(func(session *xorm.Session) (any, error) { session = session.Context(ctx) item := &entity.UserRoleRel{UserID: userID} exist, err := session.Get(item) diff --git a/internal/repo/search_common/search_repo.go b/internal/repo/search_common/search_repo.go index 314c51878..806517234 100644 --- a/internal/repo/search_common/search_repo.go +++ b/internal/repo/search_common/search_repo.go @@ -107,8 +107,8 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagIDs ub *builder.Builder qfs = qFields afs = aFields - argsQ = []interface{}{} - argsA = []interface{}{} + argsQ = []any{} + argsA = []any{} ) if order == "relevance" { @@ -212,8 +212,8 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagIDs return } - queryArgs := []interface{}{} - countArgs := []interface{}{} + queryArgs := []any{} + countArgs := []any{} queryArgs = append(queryArgs, querySQL) queryArgs = append(queryArgs, argsQ...) @@ -246,7 +246,7 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, tagID words = filterWords(words) var ( qfs = qFields - args = []interface{}{} + args = []any{} ) if order == "relevance" { if len(words) > 0 { @@ -313,8 +313,8 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, tagID args = append(args, answers) } - queryArgs := []interface{}{} - countArgs := []interface{}{} + queryArgs := []any{} + countArgs := []any{} countSQL, _, err := builder.MySQL().Select("count(*) total").From(b, "c").ToSQL() if err != nil { @@ -358,7 +358,7 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, tagIDs var ( afs = aFields - args = []interface{}{} + args = []any{} ) if order == "relevance" { if len(words) > 0 { @@ -409,8 +409,8 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, tagIDs args = append(args, questionID) } - queryArgs := []interface{}{} - countArgs := []interface{}{} + queryArgs := []any{} + countArgs := []any{} countSQL, _, err := builder.MySQL().Select("count(*) total").From(b, "c").ToSQL() if err != nil { @@ -575,9 +575,9 @@ func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte, return resultList, nil } -func addRelevanceField(searchFields, words, fields []string) (res []string, args []interface{}) { +func addRelevanceField(searchFields, words, fields []string) (res []string, args []any) { relevanceRes := []string{} - args = []interface{}{} + args = []any{} for _, searchField := range searchFields { var ( @@ -585,7 +585,7 @@ func addRelevanceField(searchFields, words, fields []string) (res []string, args replacement = "REPLACE(%s, ?, '')" replaceField = searchField replaced string - argsField = []interface{}{} + argsField = []any{} ) res = fields diff --git a/internal/repo/user/user_repo.go b/internal/repo/user/user_repo.go index a85cd79a1..1533cc5e8 100644 --- a/internal/repo/user/user_repo.go +++ b/internal/repo/user/user_repo.go @@ -51,7 +51,7 @@ func NewUserRepo(data *data.Data) usercommon.UserRepo { // AddUser add user func (ur *userRepo) AddUser(ctx context.Context, user *entity.User) (err error) { - _, err = ur.data.DB.Transaction(func(session *xorm.Session) (interface{}, error) { + _, err = ur.data.DB.Transaction(func(session *xorm.Session) (any, error) { session = session.Context(ctx) userInfo := &entity.User{} exist, err := session.Where("username = ?", user.Username).Get(userInfo) diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.go index 84b97b830..133208286 100644 --- a/internal/schema/question_schema.go +++ b/internal/schema/question_schema.go @@ -330,24 +330,24 @@ type UserAnswerInfo struct { CreateTime int `json:"create_time"` UpdateTime int `json:"update_time"` QuestionInfo struct { - Title string `json:"title"` - UrlTitle string `json:"url_title"` - Tags []interface{} `json:"tags"` + Title string `json:"title"` + UrlTitle string `json:"url_title"` + Tags []any `json:"tags"` } `json:"question_info"` } type UserQuestionInfo struct { - ID string `json:"question_id"` - Title string `json:"title"` - UrlTitle string `json:"url_title"` - VoteCount int `json:"vote_count"` - Tags []interface{} `json:"tags"` - ViewCount int `json:"view_count"` - AnswerCount int `json:"answer_count"` - CollectionCount int `json:"collection_count"` - CreatedAt int64 `json:"created_at"` - AcceptedAnswerID string `json:"accepted_answer_id"` - Status string `json:"status"` + ID string `json:"question_id"` + Title string `json:"title"` + UrlTitle string `json:"url_title"` + VoteCount int `json:"vote_count"` + Tags []any `json:"tags"` + ViewCount int `json:"view_count"` + AnswerCount int `json:"answer_count"` + CollectionCount int `json:"collection_count"` + CreatedAt int64 `json:"created_at"` + AcceptedAnswerID string `json:"accepted_answer_id"` + Status string `json:"status"` } const ( diff --git a/internal/schema/revision_schema.go b/internal/schema/revision_schema.go index 946d11653..b3ac0aadd 100644 --- a/internal/schema/revision_schema.go +++ b/internal/schema/revision_schema.go @@ -97,7 +97,7 @@ type GetRevisionResp struct { Title string `json:"title"` UrlTitle string `json:"url_title"` Content string `json:"-"` - ContentParsed interface{} `json:"content"` + ContentParsed any `json:"content"` Status int `json:"status"` CreatedAt time.Time `json:"-"` CreatedAtParsed int64 `json:"create_at"` diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.go index 76f66cb07..0e43bb420 100644 --- a/internal/schema/siteinfo_schema.go +++ b/internal/schema/siteinfo_schema.go @@ -178,9 +178,9 @@ type SiteCustomCssHTMLReq struct { // SiteThemeReq site theme config type SiteThemeReq struct { - Theme string `validate:"required,gt=0,lte=255" json:"theme"` - ThemeConfig map[string]interface{} `validate:"omitempty" json:"theme_config"` - ColorScheme string `validate:"omitempty,gt=0,lte=100" json:"color_scheme"` + Theme string `validate:"required,gt=0,lte=255" json:"theme"` + ThemeConfig map[string]any `validate:"omitempty" json:"theme_config"` + ColorScheme string `validate:"omitempty,gt=0,lte=100" json:"color_scheme"` } type SiteSeoReq struct { @@ -213,10 +213,10 @@ type SiteUsersResp SiteUsersReq // SiteThemeResp site theme response type SiteThemeResp struct { - ThemeOptions []*ThemeOption `json:"theme_options"` - Theme string `json:"theme"` - ThemeConfig map[string]interface{} `json:"theme_config"` - ColorScheme string `json:"color_scheme"` + ThemeOptions []*ThemeOption `json:"theme_options"` + Theme string `json:"theme"` + ThemeConfig map[string]any `json:"theme_config"` + ColorScheme string `json:"color_scheme"` } func (s *SiteThemeResp) TrTheme(ctx context.Context) { diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go index 7ba8817a8..d209c8f58 100644 --- a/internal/schema/user_schema.go +++ b/internal/schema/user_schema.go @@ -200,7 +200,7 @@ func (r *GetOtherUserInfoByUsernameResp) ConvertFromUserEntityWithLang(ctx conte r.SuspendedUntil = userInfo.SuspendedUntil.Unix() trans := translator.GlobalTrans.Tr(lang, "ui.dates.long_date_with_time") suspendedUntilFormatted := day.Format(userInfo.SuspendedUntil.Unix(), trans, "UTC") - r.StatusMsg = translator.TrWithData(lang, reason.UserStatusSuspendedUntil, map[string]interface{}{ + r.StatusMsg = translator.TrWithData(lang, reason.UserStatusSuspendedUntil, map[string]any{ "SuspendedUntil": suspendedUntilFormatted, }) } diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.go index feb5626ed..333806445 100644 --- a/internal/service/question_common/question.go +++ b/internal/service/question_common/question.go @@ -622,7 +622,7 @@ func (qs *QuestionCommon) SitemapCron(ctx context.Context) { } } -func (qs *QuestionCommon) SetCache(ctx context.Context, cachekey string, info interface{}) error { +func (qs *QuestionCommon) SetCache(ctx context.Context, cachekey string, info any) error { infoStr, err := json.Marshal(info) if err != nil { return errors.InternalServer(reason.UnknownError).WithError(err).WithStack() diff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.go index 92b3e0c71..cf43d68d5 100644 --- a/internal/service/siteinfo/siteinfo_service.go +++ b/internal/service/siteinfo/siteinfo_service.go @@ -183,7 +183,7 @@ func (s *SiteInfoService) SaveSiteBranding(ctx context.Context, req *schema.Site } // SaveSiteWrite save site configuration about write -func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWriteReq) (resp interface{}, err error) { +func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWriteReq) (resp any, err error) { recommendTags, reservedTags := make([]string, 0), make([]string, 0) recommendTagMapping, reservedTagMapping := make(map[string]bool), make(map[string]bool) for _, tag := range req.ReservedTags { diff --git a/internal/service/siteinfo_common/siteinfo_service.go b/internal/service/siteinfo_common/siteinfo_service.go index ef4869cc4..fda117229 100644 --- a/internal/service/siteinfo_common/siteinfo_service.go +++ b/internal/service/siteinfo_common/siteinfo_service.go @@ -56,7 +56,7 @@ type SiteInfoCommonService interface { GetSiteCustomCssHTML(ctx context.Context) (resp *schema.SiteCustomCssHTMLResp, err error) GetSiteTheme(ctx context.Context) (resp *schema.SiteThemeResp, err error) GetSiteSeo(ctx context.Context) (resp *schema.SiteSeoResp, err error) - GetSiteInfoByType(ctx context.Context, siteType string, resp interface{}) (err error) + GetSiteInfoByType(ctx context.Context, siteType string, resp any) (err error) IsBrandingFileUsed(ctx context.Context, filePath string) bool } @@ -224,7 +224,7 @@ func (s *siteInfoCommonService) EnableShortID(ctx context.Context) (enabled bool return siteSeo.IsShortLink() } -func (s *siteInfoCommonService) GetSiteInfoByType(ctx context.Context, siteType string, resp interface{}) (err error) { +func (s *siteInfoCommonService) GetSiteInfoByType(ctx context.Context, siteType string, resp any) (err error) { siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, siteType) if err != nil { return err diff --git a/pkg/converter/str.go b/pkg/converter/str.go index 40c147fdc..5164609ca 100644 --- a/pkg/converter/str.go +++ b/pkg/converter/str.go @@ -47,7 +47,7 @@ func IntToString(data int64) string { // InterfaceToString converts data to string // It will be used in template render -func InterfaceToString(data interface{}) string { +func InterfaceToString(data any) string { switch t := data.(type) { case int: i := data.(int)