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
46b4defc
Commit
46b4defc
authored
1 year ago
by
ko_oler
Browse files
Options
Downloads
Patches
Plain Diff
обновление после влития глобального идентификатора, правка тестов
parent
08aaf1e5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
log/log.go
+27
-10
27 additions, 10 deletions
log/log.go
log/log_test.go
+18
-17
18 additions, 17 deletions
log/log_test.go
with
45 additions
and
27 deletions
log/log.go
+
27
−
10
View file @
46b4defc
...
...
@@ -3,8 +3,8 @@ package log
import
(
"time"
"git.perx.ru/perxis/perxis-go/id"
pb
"git.perx.ru/perxis/perxis-go/proto/log"
"github.com/mitchellh/mapstructure"
"google.golang.org/protobuf/types/known/timestamppb"
)
...
...
@@ -34,8 +34,8 @@ type Entry struct {
Category
string
`json:"category,omitempty" bson:"category,omitempty" mapstructure:"category,omitempty"`
Component
string
`json:"component,omitempty" bson:"component,omitempty" mapstructure:"component,omitempty"`
Event
string
`json:"event,omitempty" bson:"event,omitempty" mapstructure:"event,omitempty"`
ObjectID
*
id
.
ID
`json:"object,omitempty" bson:"object,omitempty" mapstructure:"object,omitempty"`
CallerID
*
id
.
ID
`json:"caller,omitempty" bson:"caller,omitempty" mapstructure:"caller,omitempty"`
ObjectID
*
id
.
ID
`json:"object
_id
,omitempty" bson:"object
_id
,omitempty" mapstructure:"object
_id
,omitempty"`
CallerID
*
id
.
ID
`json:"caller
_id
,omitempty" bson:"caller
_id
,omitempty" mapstructure:"caller
_id
,omitempty"`
Attr
interface
{}
`json:"attr,omitempty" bson:"attr,omitempty" mapstructure:"attr,omitempty"`
Tags
[]
string
`json:"tags,omitempty" bson:"tags,omitempty" mapstructure:"tags,omitempty"`
}
...
...
@@ -59,8 +59,8 @@ func EntryToPB(entry *Entry) *pb.LogEntry {
Category
:
entry
.
Category
,
Component
:
entry
.
Component
,
Event
:
entry
.
Event
,
Object
:
entry
.
Object
,
Caller
:
entry
.
Caller
,
Object
Id
:
entry
.
Object
ID
.
String
()
,
Caller
Id
:
entry
.
Caller
ID
.
String
()
,
Attr
:
nil
,
//implement
Tags
:
entry
.
Tags
,
}
...
...
@@ -68,6 +68,8 @@ func EntryToPB(entry *Entry) *pb.LogEntry {
}
func
EntryFromPB
(
request
*
pb
.
LogEntry
)
*
Entry
{
objectID
,
_
:=
id
.
Parse
(
request
.
ObjectId
)
callerID
,
_
:=
id
.
Parse
(
request
.
CallerId
)
return
&
Entry
{
ID
:
request
.
Id
,
Timestamp
:
request
.
Timestamp
.
AsTime
(),
...
...
@@ -76,15 +78,30 @@ func EntryFromPB(request *pb.LogEntry) *Entry {
Category
:
request
.
Category
,
Component
:
request
.
Component
,
Event
:
request
.
Event
,
Object
:
request
.
O
bject
,
Caller
:
request
.
C
aller
,
Object
ID
:
o
bject
ID
,
Caller
ID
:
c
aller
ID
,
Attr
:
request
.
Attr
,
// todo: как с этим работать?
Tags
:
request
.
Tags
,
}
}
func
(
e
*
Entry
)
ToMap
()
map
[
string
]
interface
{}
{
res
:=
make
(
map
[
string
]
interface
{})
_
=
mapstructure
.
Decode
(
e
,
&
res
)
func
(
e
*
Entry
)
ToMap
()
map
[
string
]
any
{
res
:=
map
[
string
]
any
{
"id"
:
e
.
ID
,
"timestamp"
:
e
.
Timestamp
,
"log_level"
:
e
.
LogLevel
,
"message"
:
e
.
Message
,
"category"
:
e
.
Category
,
"component"
:
e
.
Component
,
"event"
:
e
.
Event
,
"object_id"
:
e
.
ObjectID
.
String
(),
"caller_id"
:
e
.
CallerID
.
String
(),
}
if
e
.
Attr
!=
nil
{
res
[
"attr"
]
=
e
.
Attr
}
if
e
.
Tags
!=
nil
{
res
[
"tags"
]
=
e
.
Tags
}
return
res
}
This diff is collapsed.
Click to expand it.
log/log_test.go
+
18
−
17
View file @
46b4defc
...
...
@@ -4,6 +4,7 @@ import (
"testing"
"time"
"git.perx.ru/perxis/perxis-go/id"
"github.com/stretchr/testify/assert"
)
...
...
@@ -16,8 +17,8 @@ func TestEntry_ToMap(t *testing.T) {
Category
string
Component
string
Event
string
Object
string
Caller
string
Object
Id
*
id
.
ID
Caller
Id
*
id
.
ID
Attr
interface
{}
Tags
[]
string
}
...
...
@@ -29,19 +30,19 @@ func TestEntry_ToMap(t *testing.T) {
{
"#1"
,
fields
{
ID
:
"1"
,
Timestamp
:
time
.
Time
{},
Message
:
"message"
,
Object
:
"/spaces/<space_id>/envs/<env_id>"
,
Caller
:
"/users/<user_id>"
,
},
map
[
string
]
interface
{}{
"id"
:
"1"
,
"timestamp"
:
map
[
string
]
interface
{}{},
"message"
:
"message"
,
"object"
:
"/spaces/<space_id>/envs/<env_id>"
,
"caller"
:
"/users/<user_id>"
,
"1"
,
time
.
Time
{},
0
,
"message"
,
""
,
""
,
""
,
id
.
NewEnvironmentID
(
"<space_id>"
,
"<env_id>"
),
id
.
NewUserID
(
"<user_id>"
),
nil
,
nil
,
},
map
[
string
]
interface
{}{
"caller_id"
:
"/users/<user_id>"
,
"category"
:
""
,
"component"
:
""
,
"event"
:
""
,
"id"
:
"1"
,
"log_level"
:
Level
(
0
),
"message"
:
"message"
,
"object_id"
:
"/spaces/<space_id>/envs/<env_id>"
,
"timestamp"
:
time
.
Date
(
1
,
time
.
January
,
1
,
0
,
0
,
0
,
0
,
time
.
UTC
)},
},
}
for
_
,
tt
:=
range
tests
{
...
...
@@ -54,12 +55,12 @@ func TestEntry_ToMap(t *testing.T) {
Category
:
tt
.
fields
.
Category
,
Component
:
tt
.
fields
.
Component
,
Event
:
tt
.
fields
.
Event
,
Object
:
tt
.
fields
.
Object
,
Caller
:
tt
.
fields
.
Caller
,
Object
ID
:
tt
.
fields
.
Object
Id
,
Caller
ID
:
tt
.
fields
.
Caller
Id
,
Attr
:
tt
.
fields
.
Attr
,
Tags
:
tt
.
fields
.
Tags
,
}
assert
.
Equal
(
t
,
e
.
ToMap
()
,
tt
.
want
)
assert
.
Equal
(
t
,
tt
.
want
,
e
.
ToMap
())
})
}
}
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