Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c917ce64
authored
Dec 28, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: streamline log processing by introducing formatUserLogs function
parent
9e25f059
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
20 deletions
+16
-20
model/log.go
+16
-20
No files found.
model/log.go
View file @
c917ce64
...
...
@@ -50,6 +50,19 @@ const (
LogTypeSystem
)
func
formatUserLogs
(
logs
[]
*
Log
)
{
for
i
:=
range
logs
{
var
otherMap
map
[
string
]
interface
{}
otherMap
=
common
.
StrToMap
(
logs
[
i
]
.
Other
)
if
otherMap
!=
nil
{
// delete admin
delete
(
otherMap
,
"admin_info"
)
}
logs
[
i
]
.
Other
=
common
.
MapToJsonStr
(
otherMap
)
logs
[
i
]
.
Id
=
logs
[
i
]
.
Id
%
1024
}
}
func
GetLogByKey
(
key
string
)
(
logs
[]
*
Log
,
err
error
)
{
if
os
.
Getenv
(
"LOG_SQL_DSN"
)
!=
""
{
var
tk
Token
...
...
@@ -60,6 +73,7 @@ func GetLogByKey(key string) (logs []*Log, err error) {
}
else
{
err
=
LOG_DB
.
Joins
(
"left join tokens on tokens.id = logs.token_id"
)
.
Where
(
"tokens.key = ?"
,
strings
.
TrimPrefix
(
key
,
"sk-"
))
.
Find
(
&
logs
)
.
Error
}
formatUserLogs
(
logs
)
return
logs
,
err
}
...
...
@@ -185,16 +199,7 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
return
nil
,
0
,
err
}
err
=
tx
.
Order
(
"id desc"
)
.
Limit
(
num
)
.
Offset
(
startIdx
)
.
Find
(
&
logs
)
.
Error
for
i
:=
range
logs
{
var
otherMap
map
[
string
]
interface
{}
otherMap
=
common
.
StrToMap
(
logs
[
i
]
.
Other
)
if
otherMap
!=
nil
{
// delete admin
delete
(
otherMap
,
"admin_info"
)
}
logs
[
i
]
.
Other
=
common
.
MapToJsonStr
(
otherMap
)
logs
[
i
]
.
Id
=
logs
[
i
]
.
Id
%
1024
}
formatUserLogs
(
logs
)
return
logs
,
total
,
err
}
...
...
@@ -205,16 +210,7 @@ func SearchAllLogs(keyword string) (logs []*Log, err error) {
func
SearchUserLogs
(
userId
int
,
keyword
string
)
(
logs
[]
*
Log
,
err
error
)
{
err
=
LOG_DB
.
Where
(
"user_id = ? and type = ?"
,
userId
,
keyword
)
.
Order
(
"id desc"
)
.
Limit
(
common
.
MaxRecentItems
)
.
Find
(
&
logs
)
.
Error
for
i
:=
range
logs
{
var
otherMap
map
[
string
]
interface
{}
otherMap
=
common
.
StrToMap
(
logs
[
i
]
.
Other
)
if
otherMap
!=
nil
{
// delete admin
delete
(
otherMap
,
"admin_info"
)
}
logs
[
i
]
.
Other
=
common
.
MapToJsonStr
(
otherMap
)
logs
[
i
]
.
Id
=
logs
[
i
]
.
Id
%
1024
}
formatUserLogs
(
logs
)
return
logs
,
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment