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.
LinkinStar04a12ee8326b
diff --git a/cmd/answer/main.go b/cmd/answer/main.goindex 0cc8ea74..8d1481ba 100644--- a/cmd/answer/main.go+++ b/cmd/answer/main.go@@ -20,7 +20,7 @@ var (// Name is the name of the projectName = "answer"// Version is the version of the project- Version = "development"+ Version = "0.0.0"// Revision is the git short commit revision numberRevision = ""// Time is the build time of the projectdiff --git a/internal/service/dashboard/dashboard_service.go b/internal/service/dashboard/dashboard_service.goindex 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.Dasif 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.goindex 68f5a450..0f93f0fd 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 {@@ -35,57 +36,60 @@ func NewSiteInfoService(// GetSiteGeneral get site info generalfunc (s *SiteInfoService) GetSiteGeneral(ctx context.Context) (resp *schema.SiteGeneralResp, err error) {+ 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 nil, errors.BadRequest(reason.SiteInfoNotFound)+ return resp, nil}-- resp = &schema.SiteGeneralResp{}_ = json.Unmarshal([]byte(siteInfo.Content), resp)return resp, nil}// GetSiteInterface get site info interfacefunc (s *SiteInfoService) GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceResp, err error) {+ 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 nil, errors.BadRequest(reason.SiteInfoNotFound)+ return resp, nil}- resp = &schema.SiteInterfaceResp{}_ = json.Unmarshal([]byte(siteInfo.Content), resp)return resp, nil}// GetSiteBranding get site info brandingfunc (s *SiteInfoService) GetSiteBranding(ctx context.Context) (resp *schema.SiteBrandingReq, err error) {+ 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 nil, errors.BadRequest(reason.SiteInfoNotFound)+ return resp, nil}- resp = &schema.SiteBrandingReq{}_ = json.Unmarshal([]byte(siteInfo.Content), resp)return resp, nil}// GetSiteWrite get site info writefunc (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 nil, errors.BadRequest(reason.SiteInfoNotFound)+ return resp, nil}- resp = &schema.SiteWriteResp{}_ = json.Unmarshal([]byte(siteInfo.Content), resp)resp.RecommendTags, err = s.tagCommonService.GetSiteWriteRecommendTag(ctx)diff --git a/internal/service/siteinfo_common/siteinfo_service.go b/internal/service/siteinfo_common/siteinfo_service.goindex 9b5006d9..36828893 100644--- a/internal/service/siteinfo_common/siteinfo_service.go+++ b/internal/service/siteinfo_common/siteinfo_service.go@@ -22,57 +22,56 @@ func NewSiteInfoCommonService(siteInfoRepo SiteInfoRepo) *SiteInfoCommonService// GetSiteGeneral get site info generalfunc (s *SiteInfoCommonService) GetSiteGeneral(ctx context.Context) (resp *schema.SiteGeneralResp, err error) {+ resp = &schema.SiteGeneralResp{}siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeGeneral)if err != nil {- return nil, err+ return resp, err}if !exist {- return nil, errors.BadRequest(reason.SiteInfoNotFound)+ return resp, errors.BadRequest(reason.SiteInfoNotFound)}-- resp = &schema.SiteGeneralResp{}_ = json.Unmarshal([]byte(siteInfo.Content), resp)return resp, nil}// GetSiteInterface get site info interfacefunc (s *SiteInfoCommonService) GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceResp, err error) {+ resp = &schema.SiteInterfaceResp{}siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeInterface)if err != nil {- return nil, err+ return resp, err}if !exist {- return nil, errors.BadRequest(reason.SiteInfoNotFound)+ return resp, errors.BadRequest(reason.SiteInfoNotFound)}- resp = &schema.SiteInterfaceResp{}_ = json.Unmarshal([]byte(siteInfo.Content), resp)return resp, nil}// GetSiteBranding get site info brandingfunc (s *SiteInfoCommonService) GetSiteBranding(ctx context.Context) (resp *schema.SiteBrandingResp, err error) {+ resp = &schema.SiteBrandingResp{}siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeBranding)if err != nil {- return nil, err+ return resp, err}if !exist {- return nil, errors.BadRequest(reason.SiteInfoNotFound)+ return resp, errors.BadRequest(reason.SiteInfoNotFound)}- resp = &schema.SiteBrandingResp{}_ = json.Unmarshal([]byte(siteInfo.Content), resp)return resp, nil}// GetSiteWrite get site info writefunc (s *SiteInfoCommonService) 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+ return resp, err}if !exist {- return nil, errors.BadRequest(reason.SiteInfoNotFound)+ return resp, errors.BadRequest(reason.SiteInfoNotFound)}- resp = &schema.SiteWriteResp{}_ = json.Unmarshal([]byte(siteInfo.Content), resp)return resp, nil}