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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
c8e1fe9f
Commit
c8e1fe9f
authored
1 year ago
by
ko_oler
Browse files
Options
Downloads
Patches
Plain Diff
- исправлено имя импорта
- добавлена функция для перевода в тип Any - исправления в FindOptions
parent
0d015cd5
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pkg/items/pagination.go
+8
-5
8 additions, 5 deletions
pkg/items/pagination.go
pkg/log/log.go
+28
-12
28 additions, 12 deletions
pkg/log/log.go
pkg/log/service.go
+5
-5
5 additions, 5 deletions
pkg/log/service.go
pkg/options/options.go
+3
-3
3 additions, 3 deletions
pkg/options/options.go
with
44 additions
and
25 deletions
pkg/items/pagination.go
+
8
−
5
View file @
c8e1fe9f
...
...
@@ -16,9 +16,12 @@ type BatchProcessor struct {
FindPublishedOptions
*
FindPublishedOptions
Filter
*
Filter
pageSize
,
pageNum
,
offset
,
limit
int
sort
[]
string
processed
int
// Deprecated использовать offset, limit
pageSize
,
pageNum
int
offset
,
limit
int
sort
[]
string
processed
int
}
func
(
b
*
BatchProcessor
)
getBatch
(
ctx
context
.
Context
)
([]
*
Item
,
bool
,
error
)
{
...
...
@@ -37,7 +40,7 @@ func (b *BatchProcessor) getBatch(ctx context.Context) ([]*Item, bool, error) {
Regular
:
b
.
FindPublishedOptions
.
Regular
,
Hidden
:
b
.
FindPublishedOptions
.
Hidden
,
Templates
:
b
.
FindPublishedOptions
.
Templates
,
FindOptions
:
*
options
.
NewFindOptions
(
b
.
pageNum
,
b
.
pageSize
,
b
.
offset
,
b
.
limit
,
b
.
sort
...
),
FindOptions
:
*
options
.
NewFindOptions
(
b
.
offset
,
b
.
limit
,
b
.
sort
...
),
},
)
}
else
{
...
...
@@ -52,7 +55,7 @@ func (b *BatchProcessor) getBatch(ctx context.Context) ([]*Item, bool, error) {
Regular
:
b
.
FindOptions
.
Regular
,
Hidden
:
b
.
FindOptions
.
Hidden
,
Templates
:
b
.
FindOptions
.
Templates
,
FindOptions
:
*
options
.
NewFindOptions
(
b
.
pageNum
,
b
.
pageSize
,
b
.
offset
,
b
.
limit
,
b
.
sort
...
),
FindOptions
:
*
options
.
NewFindOptions
(
b
.
offset
,
b
.
limit
,
b
.
sort
...
),
},
)
}
...
...
This diff is collapsed.
Click to expand it.
pkg/log/log.go
+
28
−
12
View file @
c8e1fe9f
package
log
import
(
"encoding/json"
"time"
"git.perx.ru/perxis/perxis-go/proto/log"
pb
"git.perx.ru/perxis/perxis-go/proto/log"
"github.com/golang/protobuf/ptypes/any"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/timestamppb"
wrappers
"google.golang.org/protobuf/types/known/wrapperspb"
)
type
Level
int
const
(
Info
=
Level
(
log
.
LogLevel_INFO
)
Warning
=
Level
(
log
.
LogLevel_WARNING
)
Error
=
Level
(
log
.
LogLevel_ERROR
)
Critical
=
Level
(
log
.
LogLevel_CRITICAL
)
Fatal
=
Level
(
log
.
LogLevel_FATAL
)
Info
=
Level
(
pb
.
LogLevel_INFO
)
Warning
=
Level
(
pb
.
LogLevel_WARNING
)
Error
=
Level
(
pb
.
LogLevel_ERROR
)
Critical
=
Level
(
pb
.
LogLevel_CRITICAL
)
Fatal
=
Level
(
pb
.
LogLevel_FATAL
)
)
func
(
l
Level
)
String
()
string
{
s
:=
log
.
LogLevel_name
[
int32
(
l
)]
s
:=
pb
.
LogLevel_name
[
int32
(
l
)]
if
s
==
""
{
s
=
"UNKNOWN"
}
...
...
@@ -39,24 +44,35 @@ type Entry struct {
Tags
[]
string
`json:"tags,omitempty" bson:"tags,omitempty"`
}
func
EntryToPB
(
entry
*
Entry
)
*
log
.
LogEntry
{
logEntry
:=
&
log
.
LogEntry
{
func
convertInterfaceToAny
(
v
interface
{})
(
*
any
.
Any
,
error
)
{
anyValue
:=
&
any
.
Any
{}
bytes
,
_
:=
json
.
Marshal
(
v
)
bytesValue
:=
&
wrappers
.
BytesValue
{
Value
:
bytes
,
}
err
:=
anypb
.
MarshalFrom
(
anyValue
,
bytesValue
,
proto
.
MarshalOptions
{})
return
anyValue
,
err
}
func
EntryToPB
(
entry
*
Entry
)
*
pb
.
LogEntry
{
logEntry
:=
&
pb
.
LogEntry
{
Id
:
entry
.
ID
,
Timestamp
:
timestamppb
.
New
(
entry
.
Timestamp
),
Level
:
log
.
LogLevel
(
entry
.
LogLevel
),
Level
:
pb
.
LogLevel
(
entry
.
LogLevel
),
Message
:
entry
.
Message
,
Category
:
entry
.
Category
,
Component
:
entry
.
Component
,
Event
:
entry
.
Event
,
Object
:
entry
.
Object
,
Caller
:
entry
.
Caller
,
Attr
:
nil
,
// todo: как с этим работать?
Tags
:
entry
.
Tags
,
}
logEntry
.
Attr
,
_
=
convertInterfaceToAny
(
entry
.
Attr
)
return
logEntry
}
func
EntryFromPB
(
request
*
log
.
LogEntry
)
*
Entry
{
func
EntryFromPB
(
request
*
pb
.
LogEntry
)
*
Entry
{
return
&
Entry
{
ID
:
request
.
Id
,
Timestamp
:
request
.
Timestamp
.
AsTime
(),
...
...
This diff is collapsed.
Click to expand it.
pkg/log/service.go
+
5
−
5
View file @
c8e1fe9f
...
...
@@ -5,7 +5,7 @@ import (
itemstransportgrpc
"git.perx.ru/perxis/perxis-go/pkg/items/transport/grpc"
"git.perx.ru/perxis/perxis-go/pkg/options"
"git.perx.ru/perxis/perxis-go/proto/log"
pb
"git.perx.ru/perxis/perxis-go/proto/log"
)
type
Service
interface
{
...
...
@@ -34,12 +34,12 @@ type FindResult struct {
Total
uint32
}
func
FindResultToPB
(
result
*
FindResult
)
*
log
.
FindResult
{
findResult
:=
&
log
.
FindResult
{
func
FindResultToPB
(
result
*
FindResult
)
*
pb
.
FindResult
{
findResult
:=
&
pb
.
FindResult
{
Total
:
result
.
Total
,
}
entries
:=
make
([]
*
log
.
LogEntry
,
0
,
len
(
result
.
Entries
))
entries
:=
make
([]
*
pb
.
LogEntry
,
0
,
len
(
result
.
Entries
))
for
_
,
e
:=
range
result
.
Entries
{
entries
=
append
(
entries
,
EntryToPB
(
e
))
}
...
...
@@ -55,7 +55,7 @@ func FindResultToPB(result *FindResult) *log.FindResult {
return
findResult
}
func
FindResultFromPB
(
result
*
log
.
FindResult
)
*
FindResult
{
func
FindResultFromPB
(
result
*
pb
.
FindResult
)
*
FindResult
{
findResult
:=
&
FindResult
{
Total
:
result
.
Total
,
}
...
...
This diff is collapsed.
Click to expand it.
pkg/options/options.go
+
3
−
3
View file @
c8e1fe9f
...
...
@@ -34,11 +34,11 @@ type FindOptions struct {
}
// NewFindOptions создает новые результаты поиска
func
NewFindOptions
(
pageNum
,
pageSize
,
offset
,
limit
int
,
sort
...
string
)
*
FindOptions
{
func
NewFindOptions
(
offset
,
limit
int
,
sort
...
string
)
*
FindOptions
{
return
&
FindOptions
{
PaginationOptions
:
PaginationOptions
{
PageNum
:
pageNum
,
PageSize
:
pageSize
,
PageNum
:
offset
,
PageSize
:
limit
,
Offset
:
offset
,
Limit
:
limit
,
},
...
...
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