Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

style(simple): Simplify code

LinkinStara4f5f8ecc30a
diff --git a/internal/base/constant/constant.go b/internal/base/constant/constant.go
index a1d09667..40990b93 100644
--- a/internal/base/constant/constant.go
+++ b/internal/base/constant/constant.go
@@ -69,8 +69,5 @@ const (
func ExistInPathIgnore(name string) bool {
_, ok := PathIgnoreMap[name]
- if ok {
- return true
- }
- return false
+ return ok
}
diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go
index bfc2299f..2c7eaec7 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -104,7 +104,7 @@ func (tc *TemplateController) Index(ctx *gin.Context) {
}
siteInfo := tc.SiteInfo(ctx)
- siteInfo.Canonical = fmt.Sprintf("%s", siteInfo.General.SiteUrl)
+ siteInfo.Canonical = siteInfo.General.SiteUrl
UrlUseTitle := false
if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionIDAndTitle {
diff --git a/internal/controller/template_render/controller.go b/internal/controller/template_render/controller.go
index bf5d5f8d..f44c1ea6 100644
--- a/internal/controller/template_render/controller.go
+++ b/internal/controller/template_render/controller.go
@@ -76,21 +76,21 @@ func Paginator(page, pageSize int, nums int64) *schema.Paginator {
prevpage = page - 1
nextpage = int(math.Min(float64(totalpages), float64(page+1)))
pages = make([]int, 5)
- for i, _ := range pages {
+ for i := range pages {
pages[i] = start + i
}
case page >= 3 && totalpages > 5:
start := page - 3 + 1
pages = make([]int, 5)
prevpage = page - 3
- for i, _ := range pages {
+ for i := range pages {
pages[i] = start + i
}
prevpage = page - 1
nextpage = page + 1
default:
pages = make([]int, int(math.Min(5, float64(totalpages))))
- for i, _ := range pages {
+ for i := range pages {
pages[i] = i + 1
}
prevpage = int(math.Max(float64(1), float64(page-1)))
diff --git a/internal/install/install_controller.go b/internal/install/install_controller.go
index 62cbdf87..561c6dc4 100644
--- a/internal/install/install_controller.go
+++ b/internal/install/install_controller.go
@@ -187,5 +187,4 @@ func InitBaseInfo(ctx *gin.Context) {
time.Sleep(1 * time.Second)
os.Exit(0)
}()
- return
}
diff --git a/internal/migrations/init.go b/internal/migrations/init.go
index 86f7e60c..5bbc4631 100644
--- a/internal/migrations/init.go
+++ b/internal/migrations/init.go
@@ -116,6 +116,9 @@ func initSiteInfo(engine *xorm.Engine, language, siteName, siteURL, contactEmail
Content: string(generalDataBytes),
Status: 1,
})
+ if err != nil {
+ return err
+ }
loginConfig := map[string]bool{
"allow_new_registrations": true,
diff --git a/internal/service/export/email_service.go b/internal/service/export/email_service.go
index e89dfb19..9f078224 100644
--- a/internal/service/export/email_service.go
+++ b/internal/service/export/email_service.go
@@ -277,6 +277,9 @@ func (es *EmailService) TestTemplate(ctx context.Context) (title, body string, e
return "", "", fmt.Errorf("email test body template parse error: %s", err)
}
tmpl, err = template.New("test_body").Parse(ec.TestBody)
+ if err != nil {
+ return "", "", fmt.Errorf("test_body template parse error: %s", err)
+ }
err = tmpl.Execute(bodyBuf, templateData)
if err != nil {
return "", "", err
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index 4d8c1b98..7a4635a0 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -1044,9 +1044,6 @@ func (qs *QuestionService) SitemapCron(ctx context.Context) {
if setCacheErr := qs.SetCache(ctx, schema.SitemapCachekey, data); setCacheErr != nil {
log.Errorf("set sitemap cron SetCache failed: %s", setCacheErr)
}
-
- return
-
}
func (qs *QuestionService) SetCache(ctx context.Context, cachekey string, info interface{}) error {
diff --git a/internal/service/report_backyard/report_backyard.go b/internal/service/report_backyard/report_backyard.go
index 69b87c85..2ab1a595 100644
--- a/internal/service/report_backyard/report_backyard.go
+++ b/internal/service/report_backyard/report_backyard.go
@@ -2,6 +2,7 @@ package report_backyard
import (
"context"
+
"github.com/answerdev/answer/internal/service/config"
"github.com/answerdev/answer/pkg/htmltext"
@@ -84,9 +85,15 @@ func (rs *ReportBackyardService) ListReportPage(ctx context.Context, dto schema.
// flagged users
flaggedUsers, err = rs.commonUser.BatchUserBasicInfoByID(ctx, flaggedUserIds)
+ if err != nil {
+ return nil, err
+ }
// flag users
users, err = rs.commonUser.BatchUserBasicInfoByID(ctx, userIds)
+ if err != nil {
+ return nil, err
+ }
for _, r := range resp {
r.ReportedUser = flaggedUsers[r.ReportedUserID]
r.ReportUser = users[r.UserID]
diff --git a/internal/service/revision_service.go b/internal/service/revision_service.go
index 84624cea..bb65db32 100644
--- a/internal/service/revision_service.go
+++ b/internal/service/revision_service.go
@@ -305,7 +305,7 @@ func (rs *RevisionService) GetUnreviewedRevisionPage(ctx context.Context, req *s
}
if exists {
var uinfo schema.UserBasicInfo
- err = copier.Copy(&uinfo, userInfo)
+ _ = copier.Copy(&uinfo, userInfo)
item.UnreviewedInfo.UserInfo = uinfo
}
revisionResp = append(revisionResp, item)
diff --git a/internal/service/role/role_service.go b/internal/service/role/role_service.go
index bebad7c8..ae18f762 100644
--- a/internal/service/role/role_service.go
+++ b/internal/service/role/role_service.go
@@ -81,5 +81,4 @@ func (rs *RoleService) translateRole(ctx context.Context, role *entity.Role) {
role.Name = translator.GlobalTrans.Tr(handler.GetLangByCtx(ctx), trRoleNameModerator)
role.Description = translator.GlobalTrans.Tr(handler.GetLangByCtx(ctx), trRoleDescriptionModerator)
}
- return
}
diff --git a/internal/service/search_parser/search_parser.go b/internal/service/search_parser/search_parser.go
index bd8db3f9..781247f7 100644
--- a/internal/service/search_parser/search_parser.go
+++ b/internal/service/search_parser/search_parser.go
@@ -49,7 +49,7 @@ func (sp *SearchParser) ParseStructure(dto *schema.SearchDTO) (
all = 0
q = 0
a = 0
- withWords = []string{}
+ withWords []string
limitWords = 5
)
@@ -196,7 +196,7 @@ func (sp *SearchParser) parseUserID(query *string, currentUserID string) (userID
userID = user.ID
q = re.ReplaceAllString(q, "")
}
- } else if strings.Index(q, exprMe) != -1 {
+ } else if strings.Contains(q, exprMe) {
userID = currentUserID
q = strings.ReplaceAll(q, exprMe, "")
}
@@ -247,7 +247,7 @@ func (sp *SearchParser) parseNotAccepted(query *string) (notAccepted bool) {
expr = `hasaccepted:no`
)
- if strings.Index(q, expr) != -1 {
+ if strings.Contains(q, expr) {
q = strings.ReplaceAll(q, expr, "")
notAccepted = true
}
@@ -263,7 +263,7 @@ func (sp *SearchParser) parseIsQuestion(query *string) (isQuestion bool) {
expr = `is:question`
)
- if strings.Index(q, expr) == 0 {
+ if strings.Contains(q, expr) {
q = strings.ReplaceAll(q, expr, "")
isQuestion = true
}
@@ -316,7 +316,7 @@ func (sp *SearchParser) parseAccepted(query *string) (accepted bool) {
expr = `isaccepted:yes`
)
- if strings.Index(q, expr) != -1 {
+ if strings.Contains(q, expr) {
accepted = true
strings.ReplaceAll(q, expr, "")
}
@@ -350,7 +350,7 @@ func (sp *SearchParser) parseIsAnswer(query *string) (isAnswer bool) {
expr = `is:answer`
)
- if strings.Index(q, expr) != -1 {
+ if strings.Contains(q, expr) {
isAnswer = true
q = strings.ReplaceAll(q, expr, "")
}
diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.go
index 4f167bd9..6af946bb 100644
--- a/internal/service/tag_common/tag_common.go
+++ b/internal/service/tag_common/tag_common.go
@@ -162,6 +162,9 @@ func (ts *TagCommonService) SetTagsAttribute(ctx context.Context, tags []string,
default:
return
}
+ if err != nil {
+ return err
+ }
err = ts.tagCommonRepo.UpdateTagsAttribute(ctx, tagslist, attribute, false)
if err != nil {
return err
@@ -439,7 +442,7 @@ func (ts *TagCommonService) CheckTagsIsChange(ctx context.Context, tagNameList,
check[item] = true
}
for _, value := range check {
- if value == false {
+ if !value {
return true
}
}