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
01ef43b6
Commit
01ef43b6
authored
1 year ago
by
ensiouel
Browse files
Options
Downloads
Patches
Plain Diff
для items добавлен middleware для отправки логов в log сервис
parent
250b7e3f
Branches
feature/PRXS-1891-ServiceLogMiddleware
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/items/item.go
+11
-0
11 additions, 0 deletions
pkg/items/item.go
pkg/items/middleware/log_service_middleware.go
+207
-0
207 additions, 0 deletions
pkg/items/middleware/log_service_middleware.go
with
218 additions
and
0 deletions
pkg/items/item.go
+
11
−
0
View file @
01ef43b6
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"context"
"context"
"fmt"
"fmt"
"reflect"
"reflect"
"strings"
"time"
"time"
"git.perx.ru/perxis/perxis-go/pkg/data"
"git.perx.ru/perxis/perxis-go/pkg/data"
...
@@ -135,6 +136,16 @@ func (i *Item) Clone() *Item {
...
@@ -135,6 +136,16 @@ func (i *Item) Clone() *Item {
return
&
itm
return
&
itm
}
}
func
(
i
Item
)
ObjectID
(
kv
...
string
)
string
{
path
:=
[]
string
{
"spaces"
,
i
.
SpaceID
,
"envs"
,
i
.
EnvID
,
"items"
,
i
.
ID
,
}
path
=
append
(
path
,
kv
...
)
return
strings
.
Join
(
path
,
"/"
)
}
func
(
i
*
Item
)
ToMap
()
map
[
string
]
interface
{}
{
func
(
i
*
Item
)
ToMap
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
return
map
[
string
]
interface
{}{
"id"
:
i
.
ID
,
"id"
:
i
.
ID
,
...
...
This diff is collapsed.
Click to expand it.
pkg/items/middleware/log_service_middleware.go
0 → 100644
+
207
−
0
View file @
01ef43b6
package
middleware
import
(
"context"
"git.perx.ru/perxis/perxis-go/pkg/items"
"git.perx.ru/perxis/perxis-go/pkg/schema"
"go.uber.org/zap"
)
type
logService
struct
{
logger
*
zap
.
Logger
next
items
.
Items
}
func
LogServiceMiddleware
(
logger
*
zap
.
Logger
)
Middleware
{
logger
=
logger
.
With
(
zap
.
String
(
"component"
,
"Items.Service"
),
)
return
func
(
next
items
.
Items
)
items
.
Items
{
return
&
logService
{
logger
:
logger
,
next
:
next
,
}
}
}
func
(
m
*
logService
)
Create
(
ctx
context
.
Context
,
item
*
items
.
Item
,
opts
...*
items
.
CreateOptions
)
(
created
*
items
.
Item
,
err
error
)
{
level
:=
zap
.
InfoLevel
created
,
err
=
m
.
next
.
Create
(
ctx
,
item
,
opts
...
)
if
err
!=
nil
{
level
=
zap
.
WarnLevel
}
if
created
!=
nil
{
item
=
created
}
m
.
logger
.
Log
(
level
,
"create item"
,
zap
.
String
(
"event"
,
"Items.Create"
),
zap
.
String
(
"object"
,
item
.
ObjectID
()),
zap
.
String
(
"caller"
,
ctx
.
Value
(
"caller"
)
.
(
string
)),
// TODO Решить, как заполнять это поле
)
return
}
func
(
m
*
logService
)
Introspect
(
ctx
context
.
Context
,
item
*
items
.
Item
,
opts
...*
items
.
IntrospectOptions
)
(
itm
*
items
.
Item
,
sch
*
schema
.
Schema
,
err
error
)
{
return
m
.
next
.
Introspect
(
ctx
,
item
,
opts
...
)
}
func
(
m
*
logService
)
Get
(
ctx
context
.
Context
,
spaceId
,
envId
,
collectionId
,
itemId
string
,
options
...*
items
.
GetOptions
)
(
item
*
items
.
Item
,
err
error
)
{
return
m
.
next
.
Get
(
ctx
,
spaceId
,
envId
,
collectionId
,
itemId
,
options
...
)
}
func
(
m
*
logService
)
Find
(
ctx
context
.
Context
,
spaceId
,
envId
,
collectionId
string
,
filter
*
items
.
Filter
,
options
...*
items
.
FindOptions
)
(
items
[]
*
items
.
Item
,
total
int
,
err
error
)
{
return
m
.
next
.
Find
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
func
(
m
*
logService
)
Update
(
ctx
context
.
Context
,
item
*
items
.
Item
,
options
...*
items
.
UpdateOptions
)
(
err
error
)
{
level
:=
zap
.
InfoLevel
err
=
m
.
next
.
Update
(
ctx
,
item
,
options
...
)
if
err
!=
nil
{
level
=
zap
.
WarnLevel
}
m
.
logger
.
Log
(
level
,
"update item"
,
zap
.
String
(
"event"
,
"Items.Update"
),
zap
.
String
(
"object"
,
item
.
ObjectID
(
"revs"
,
item
.
RevisionID
)),
zap
.
String
(
"caller"
,
ctx
.
Value
(
"caller"
)
.
(
string
)),
)
return
}
func
(
m
*
logService
)
Delete
(
ctx
context
.
Context
,
item
*
items
.
Item
,
options
...*
items
.
DeleteOptions
)
(
err
error
)
{
level
:=
zap
.
InfoLevel
err
=
m
.
next
.
Delete
(
ctx
,
item
,
options
...
)
if
err
!=
nil
{
level
=
zap
.
WarnLevel
}
m
.
logger
.
Log
(
level
,
"delete item"
,
zap
.
String
(
"event"
,
"Items.Delete"
),
zap
.
String
(
"object"
,
item
.
ObjectID
()),
zap
.
String
(
"caller"
,
ctx
.
Value
(
"caller"
)
.
(
string
)),
)
return
}
func
(
m
*
logService
)
Undelete
(
ctx
context
.
Context
,
item
*
items
.
Item
,
options
...*
items
.
UndeleteOptions
)
(
err
error
)
{
level
:=
zap
.
InfoLevel
err
=
m
.
next
.
Undelete
(
ctx
,
item
,
options
...
)
if
err
!=
nil
{
level
=
zap
.
WarnLevel
}
m
.
logger
.
Log
(
level
,
"undelete item"
,
zap
.
String
(
"event"
,
"Items.Undelete"
),
zap
.
String
(
"object"
,
item
.
ObjectID
()),
zap
.
String
(
"caller"
,
ctx
.
Value
(
"caller"
)
.
(
string
)),
)
return
}
func
(
m
*
logService
)
Publish
(
ctx
context
.
Context
,
item
*
items
.
Item
,
options
...*
items
.
PublishOptions
)
(
err
error
)
{
level
:=
zap
.
InfoLevel
err
=
m
.
next
.
Publish
(
ctx
,
item
,
options
...
)
if
err
!=
nil
{
level
=
zap
.
WarnLevel
}
m
.
logger
.
Log
(
level
,
"publish item"
,
zap
.
String
(
"event"
,
"Items.Publish"
),
zap
.
String
(
"object"
,
item
.
ObjectID
()),
zap
.
String
(
"caller"
,
ctx
.
Value
(
"caller"
)
.
(
string
)),
)
return
}
func
(
m
*
logService
)
Unpublish
(
ctx
context
.
Context
,
item
*
items
.
Item
,
options
...*
items
.
UnpublishOptions
)
(
err
error
)
{
level
:=
zap
.
InfoLevel
err
=
m
.
next
.
Unpublish
(
ctx
,
item
,
options
...
)
if
err
!=
nil
{
level
=
zap
.
WarnLevel
}
m
.
logger
.
Log
(
level
,
"unpublish item"
,
zap
.
String
(
"event"
,
"Items.Unpublish"
),
zap
.
String
(
"object"
,
item
.
ObjectID
()),
zap
.
String
(
"caller"
,
ctx
.
Value
(
"caller"
)
.
(
string
)),
)
return
}
func
(
m
*
logService
)
GetPublished
(
ctx
context
.
Context
,
spaceId
,
envId
,
collectionId
,
itemId
string
,
options
...*
items
.
GetPublishedOptions
)
(
item
*
items
.
Item
,
err
error
)
{
return
m
.
next
.
GetPublished
(
ctx
,
spaceId
,
envId
,
collectionId
,
itemId
,
options
...
)
}
func
(
m
*
logService
)
FindPublished
(
ctx
context
.
Context
,
spaceId
,
envId
,
collectionId
string
,
filter
*
items
.
Filter
,
options
...*
items
.
FindPublishedOptions
)
(
items
[]
*
items
.
Item
,
total
int
,
err
error
)
{
return
m
.
next
.
FindPublished
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
func
(
m
*
logService
)
GetRevision
(
ctx
context
.
Context
,
spaceId
,
envId
,
collectionId
,
itemId
,
revisionId
string
,
options
...*
items
.
GetRevisionOptions
)
(
item
*
items
.
Item
,
err
error
)
{
return
m
.
next
.
GetRevision
(
ctx
,
spaceId
,
envId
,
collectionId
,
itemId
,
revisionId
,
options
...
)
}
func
(
m
*
logService
)
ListRevisions
(
ctx
context
.
Context
,
spaceId
,
envId
,
collectionId
,
itemId
string
,
options
...*
items
.
ListRevisionsOptions
)
(
items
[]
*
items
.
Item
,
err
error
)
{
return
m
.
next
.
ListRevisions
(
ctx
,
spaceId
,
envId
,
collectionId
,
itemId
,
options
...
)
}
func
(
m
*
logService
)
Archive
(
ctx
context
.
Context
,
item
*
items
.
Item
,
options
...*
items
.
ArchiveOptions
)
(
err
error
)
{
level
:=
zap
.
InfoLevel
err
=
m
.
next
.
Archive
(
ctx
,
item
,
options
...
)
if
err
!=
nil
{
level
=
zap
.
WarnLevel
}
m
.
logger
.
Log
(
level
,
"archive item"
,
zap
.
String
(
"event"
,
"Items.Archive"
),
zap
.
String
(
"object"
,
item
.
ObjectID
()),
zap
.
String
(
"caller"
,
ctx
.
Value
(
"caller"
)
.
(
string
)),
)
return
}
func
(
m
*
logService
)
FindArchived
(
ctx
context
.
Context
,
spaceId
,
envId
,
collectionId
string
,
filter
*
items
.
Filter
,
options
...*
items
.
FindArchivedOptions
)
(
items
[]
*
items
.
Item
,
total
int
,
err
error
)
{
return
m
.
next
.
FindArchived
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
func
(
m
*
logService
)
Unarchive
(
ctx
context
.
Context
,
item
*
items
.
Item
,
options
...*
items
.
UnarchiveOptions
)
(
err
error
)
{
level
:=
zap
.
InfoLevel
err
=
m
.
next
.
Unarchive
(
ctx
,
item
,
options
...
)
if
err
!=
nil
{
level
=
zap
.
WarnLevel
}
m
.
logger
.
Log
(
level
,
"unarchive item"
,
zap
.
String
(
"event"
,
"Items.Unarchive"
),
zap
.
String
(
"object"
,
item
.
ObjectID
()),
zap
.
String
(
"caller"
,
ctx
.
Value
(
"caller"
)
.
(
string
)),
)
return
}
func
(
m
*
logService
)
Aggregate
(
ctx
context
.
Context
,
spaceId
,
envId
,
collectionId
string
,
filter
*
items
.
Filter
,
options
...*
items
.
AggregateOptions
)
(
result
map
[
string
]
interface
{},
err
error
)
{
return
m
.
next
.
Aggregate
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
func
(
m
*
logService
)
AggregatePublished
(
ctx
context
.
Context
,
spaceId
,
envId
,
collectionId
string
,
filter
*
items
.
Filter
,
options
...*
items
.
AggregatePublishedOptions
)
(
result
map
[
string
]
interface
{},
err
error
)
{
return
m
.
next
.
AggregatePublished
(
ctx
,
spaceId
,
envId
,
collectionId
,
filter
,
options
...
)
}
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