From 4eabefc8e4cf39d27c65eff63f86d29f20c44f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=20=E8=8E=B9=E6=B3=A2?= Date: Wed, 20 Jul 2022 16:45:36 +0800 Subject: [PATCH] pageRequest default --- types/query/format_page_request.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/types/query/format_page_request.go b/types/query/format_page_request.go index 52df2be..2aa8b7b 100644 --- a/types/query/format_page_request.go +++ b/types/query/format_page_request.go @@ -3,15 +3,20 @@ package query import sdk "github.com/irisnet/core-sdk-go/types" const ( - PageReqNilErrMsg = "pageRequest error: PageRequest cannot be nil" CountTotalErrMsg = "pageRequest error: CountTotal is not supported, must be false" LimitErrMsg = "pageRequest error: Limit cannot be empty and cannot exceed 100" + OffsetKeyErrMsg = "pageRequest error: Only one Offset or Key is allowed" ) func FormatPageRequest(pageReq *PageRequest) (*PageRequest, sdk.Error) { if pageReq == nil { - return pageReq, sdk.Wrapf(PageReqNilErrMsg) + return &PageRequest{ + Offset: 0, + Limit: 100, + CountTotal: false, + }, nil } + if pageReq.CountTotal { return pageReq, sdk.Wrapf(CountTotalErrMsg) } @@ -20,5 +25,9 @@ func FormatPageRequest(pageReq *PageRequest) (*PageRequest, sdk.Error) { return pageReq, sdk.Wrapf(LimitErrMsg) } + if pageReq.Offset != 0 && len(pageReq.Key) > 0 { + return pageReq, sdk.Wrapf(OffsetKeyErrMsg) + } + return pageReq, nil }