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.

fix: set default version is 0.0.0, return site info is empty when site info can't found. fix dashboard return error when cache not found.

LinkinStar3a713fb0c1bb
diff --git a/cmd/answer/main.go b/cmd/answer/main.go
index 0cc8ea74..8d1481ba 100644
--- a/cmd/answer/main.go
+++ b/cmd/answer/main.go
@@ -20,7 +20,7 @@ var (
// Name is the name of the project
Name = "answer"
// Version is the version of the project
- Version = "development"
+ Version = "0.0.0"
// Revision is the git short commit revision number
Revision = ""
// Time is the build time of the project
diff --git a/internal/service/dashboard/dashboard_service.go b/internal/service/dashboard/dashboard_service.go
index af462823..8495ab0a 100644
--- a/internal/service/dashboard/dashboard_service.go
+++ b/internal/service/dashboard/dashboard_service.go
@@ -76,17 +76,16 @@ func (ds *DashboardService) StatisticalByCache(ctx context.Context) (*schema.Das
if err != nil {
info, statisticalErr := ds.Statistical(ctx)
if statisticalErr != nil {
- return dashboardInfo, err
+ return nil, statisticalErr
}
- setCacheErr := ds.SetCache(ctx, info)
- if setCacheErr != nil {
- log.Error("ds.SetCache", setCacheErr)
+ if setCacheErr := ds.SetCache(ctx, info); setCacheErr != nil {
+ log.Errorf("set dashboard statistical failed: %s", setCacheErr)
}
- return info, err
+ return info, nil
}
- err = json.Unmarshal([]byte(infoStr), dashboardInfo)
- if err != nil {
- return dashboardInfo, err
+ if err = json.Unmarshal([]byte(infoStr), dashboardInfo); err != nil {
+ log.Errorf("parsing dashboard information failed: %s", err)
+ return nil, errors.InternalServer(reason.UnknownError)
}
startTime := time.Now().Unix() - schema.AppStartTime.Unix()
dashboardInfo.AppStartTime = fmt.Sprintf("%d", startTime)
diff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.go
index 972ea21a..6846eb21 100644
--- a/internal/service/siteinfo/siteinfo_service.go
+++ b/internal/service/siteinfo/siteinfo_service.go
@@ -14,6 +14,7 @@ import (
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
"github.com/jinzhu/copier"
"github.com/segmentfault/pacman/errors"
+ "github.com/segmentfault/pacman/log"
)
type SiteInfoService struct {
@@ -38,7 +39,8 @@ func (s *SiteInfoService) GetSiteGeneral(ctx context.Context) (resp *schema.Site
resp = &schema.SiteGeneralResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeGeneral)
if err != nil {
- return nil, err
+ log.Error(err)
+ return resp, nil
}
if !exist {
return resp, nil
@@ -52,7 +54,8 @@ func (s *SiteInfoService) GetSiteInterface(ctx context.Context) (resp *schema.Si
resp = &schema.SiteInterfaceResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeInterface)
if err != nil {
- return nil, err
+ log.Error(err)
+ return resp, nil
}
if !exist {
return resp, nil
@@ -66,7 +69,8 @@ func (s *SiteInfoService) GetSiteBranding(ctx context.Context) (resp *schema.Sit
resp = &schema.SiteBrandingReq{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeBranding)
if err != nil {
- return nil, err
+ log.Error(err)
+ return resp, nil
}
if !exist {
return resp, nil
@@ -76,11 +80,12 @@ func (s *SiteInfoService) GetSiteBranding(ctx context.Context) (resp *schema.Sit
}
// GetSiteWrite get site info write
-func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWriteReq, err error) {
- resp = &schema.SiteWriteReq{}
+func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWriteResp, err error) {
+ resp = &schema.SiteWriteResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeWrite)
if err != nil {
- return nil, err
+ log.Error(err)
+ return resp, nil
}
if !exist {
return resp, nil
diff --git a/internal/service/siteinfo_common/siteinfo_service.go b/internal/service/siteinfo_common/siteinfo_service.go
index 6fb16ddd..97d6006f 100644
--- a/internal/service/siteinfo_common/siteinfo_service.go
+++ b/internal/service/siteinfo_common/siteinfo_service.go
@@ -23,7 +23,7 @@ func (s *SiteInfoCommonService) GetSiteGeneral(ctx context.Context) (resp *schem
resp = &schema.SiteGeneralResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeGeneral)
if err != nil {
- return nil, err
+ return resp, err
}
if !exist {
return resp, nil
@@ -37,7 +37,7 @@ func (s *SiteInfoCommonService) GetSiteInterface(ctx context.Context) (resp *sch
resp = &schema.SiteInterfaceResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeInterface)
if err != nil {
- return nil, err
+ return resp, err
}
if !exist {
return resp, nil
@@ -51,7 +51,7 @@ func (s *SiteInfoCommonService) GetSiteBranding(ctx context.Context) (resp *sche
resp = &schema.SiteBrandingResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeBranding)
if err != nil {
- return nil, err
+ return resp, err
}
if !exist {
return resp, nil
@@ -65,7 +65,7 @@ func (s *SiteInfoCommonService) GetSiteWrite(ctx context.Context) (resp *schema.
resp = &schema.SiteWriteResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeWrite)
if err != nil {
- return nil, err
+ return resp, err
}
if !exist {
return resp, nil