style(simple): Simplify code

This commit is contained in:
LinkinStar 2022-12-16 14:41:20 +08:00
parent fb4d0cc3cd
commit a4f5f8ecc3
12 changed files with 29 additions and 21 deletions

View File

@ -69,8 +69,5 @@ const (
func ExistInPathIgnore(name string) bool {
_, ok := PathIgnoreMap[name]
if ok {
return true
}
return false
return ok
}

View File

@ -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 {

View File

@ -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)))

View File

@ -187,5 +187,4 @@ func InitBaseInfo(ctx *gin.Context) {
time.Sleep(1 * time.Second)
os.Exit(0)
}()
return
}

View File

@ -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,

View File

@ -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

View File

@ -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 {

View File

@ -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]

View File

@ -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)

View File

@ -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
}

View File

@ -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, "")
}

View File

@ -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
}
}