Skip to content

Commit

Permalink
change '*[]' to '[]'
Browse files Browse the repository at this point in the history
  • Loading branch information
SchwarzSail committed Jan 13, 2025
1 parent a3242dd commit f8d11ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
10 changes: 3 additions & 7 deletions internal/common/pack/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ import (
db "github.com/west2-online/fzuhelper-server/pkg/db/model"
)

func BuildNoticeList(notices *[]db.Notice) []*model.NoticeInfo {
if notices == nil {
return nil
}
rows := *notices
list := make([]*model.NoticeInfo, len(rows))
for i, notice := range rows {
func BuildNoticeList(notices []db.Notice) []*model.NoticeInfo {
list := make([]*model.NoticeInfo, len(notices))
for i, notice := range notices {
list[i] = &model.NoticeInfo{
Title: &notice.Title,
Url: &notice.URL,
Expand Down
2 changes: 1 addition & 1 deletion internal/common/service/get_notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/west2-online/jwch"
)

func (s *CommonService) GetNotice(pageNum int) (list *[]model.Notice, total int, err error) {
func (s *CommonService) GetNotice(pageNum int) (list []model.Notice, total int, err error) {
list, err = s.db.Notice.GetNoticeByPage(s.ctx, pageNum)
if err != nil {
return nil, 0, fmt.Errorf("CommonService.GetNotice get notice from database:%w", err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/db/notice/get_notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"github.com/west2-online/fzuhelper-server/pkg/errno"
)

func (d *DBNotice) GetNoticeByPage(ctx context.Context, pageNum int) (notices *[]model.Notice, err error) {
var list []model.Notice
func (d *DBNotice) GetNoticeByPage(ctx context.Context, pageNum int) (list []model.Notice, err error) {
// 不使用[]*的原因:Find 返回多个结果时,只能使用[]
offset := (pageNum - 1) * constants.NoticePageSize
if err := d.client.WithContext(ctx).Limit(constants.NoticePageSize).Offset(offset).Find(&list).Error; err != nil {
return nil, errno.Errorf(errno.InternalDatabaseErrorCode, "dal.GetNoticeByPage error: %s", err)
}
return &list, nil
return list, nil

Check warning on line 33 in pkg/db/notice/get_notice.go

View check run for this annotation

Codecov / codecov/patch

pkg/db/notice/get_notice.go#L27-L33

Added lines #L27 - L33 were not covered by tests
}

0 comments on commit f8d11ee

Please sign in to comment.