Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
390c4294
Commit
390c4294
authored
1 year ago
by
ko_oler
Browse files
Options
Downloads
Patches
Plain Diff
добавлены методы FindOptionsFromPB и FindOptionsToPB
parent
6b60cd37
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/options/options.go
+55
-1
55 additions, 1 deletion
pkg/options/options.go
with
55 additions
and
1 deletion
pkg/options/options.go
+
55
−
1
View file @
390c4294
package
options
package
options
import
"time"
import
(
"time"
commonpb
"git.perx.ru/perxis/perxis-go/proto/common"
)
// SortOptions настройки сортировки результатов
// SortOptions настройки сортировки результатов
type
SortOptions
struct
{
type
SortOptions
struct
{
...
@@ -82,6 +86,56 @@ func MergeFindOptions(opts ...interface{}) *FindOptions {
...
@@ -82,6 +86,56 @@ func MergeFindOptions(opts ...interface{}) *FindOptions {
return
fo
return
fo
}
}
func
FindOptionsFromPB
(
protoOpts
*
commonpb
.
FindOptions
)
*
FindOptions
{
if
protoOpts
==
nil
{
return
nil
}
fo
:=
&
FindOptions
{
SortOptions
:
SortOptions
{
Sort
:
protoOpts
.
Sort
,
},
PaginationOptions
:
PaginationOptions
{
Offset
:
int
(
protoOpts
.
Offset
),
Limit
:
int
(
protoOpts
.
Limit
),
},
FieldOptions
:
FieldOptions
{
Fields
:
protoOpts
.
Fields
,
ExcludeFields
:
protoOpts
.
ExcludeFields
,
},
}
if
fo
.
Offset
==
0
&&
fo
.
Limit
==
0
&&
fo
.
PageSize
!=
0
{
fo
.
Offset
=
fo
.
PageSize
*
(
fo
.
PageNum
-
1
)
fo
.
Limit
=
fo
.
PageSize
}
return
fo
}
func
FindOptionsToPB
(
opts
*
FindOptions
)
*
commonpb
.
FindOptions
{
if
opts
==
nil
{
return
nil
}
fo
:=
&
commonpb
.
FindOptions
{
Sort
:
opts
.
Sort
,
PageNum
:
int32
(
opts
.
PageNum
),
PageSize
:
int32
(
opts
.
PageSize
),
Offset
:
int32
(
opts
.
Offset
),
Limit
:
int32
(
opts
.
Limit
),
Fields
:
opts
.
Fields
,
ExcludeFields
:
opts
.
ExcludeFields
,
}
if
fo
.
PageSize
!=
0
&&
fo
.
Limit
==
0
{
fo
.
Limit
=
fo
.
PageSize
fo
.
Offset
=
fo
.
PageSize
*
(
fo
.
PageNum
-
1
)
}
if
fo
.
Limit
!=
0
&&
fo
.
PageSize
==
0
{
fo
.
PageSize
=
fo
.
Limit
fo
.
PageNum
=
fo
.
Offset
/
fo
.
Limit
}
return
fo
}
type
TimeFilter
struct
{
type
TimeFilter
struct
{
Before
,
After
time
.
Time
Before
,
After
time
.
Time
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment