Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
broadcast_cloud
/
go-tool
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
126b2bc1
authored
Sep 06, 2021
by
swh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log
parent
1b1b9a55
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
2 deletions
+83
-2
logOperation/logOperation.go
+52
-0
utils/utils.go
+31
-2
No files found.
logOperation/logOperation.go
0 → 100644
View file @
126b2bc1
package
logOperation
import
(
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/zjswh/go-tool/utils"
"time"
)
var
ApiMap
=
map
[
string
][]
string
{
"/v1/coupon/market/Discount/create"
:
[]
string
{
"创建优惠券"
,
"活动管理-优惠券"
},
"/v1/coupon/market/Discount/update"
:
[]
string
{
"修改优惠券"
,
"活动管理-优惠券"
},
"/v1/coupon/market/Discount/delete"
:
[]
string
{
"删除优惠券"
,
"活动管理-优惠券"
},
"/v1/coupon/market/Discount/saveInclude"
:
[]
string
{
"配置优惠券"
,
"活动管理-优惠券"
},
"/v1/coupon/market/DiscountDetail/writeOff"
:
[]
string
{
"核销优惠券"
,
"活动管理-优惠券"
},
}
const
LogPushUrl
=
"http://consoleapi.guangdianyun.tv/v1/log/operation"
func
Push
(
c
*
gin
.
Context
,
XCaStage
string
,
data
interface
{})
{
path
:=
c
.
Request
.
URL
.
Path
method
:=
c
.
Request
.
Method
token
:=
c
.
Request
.
Header
.
Get
(
"token"
)
ip
:=
c
.
ClientIP
()
if
_
,
ok
:=
ApiMap
[
path
];
!
ok
{
return
}
reqMap
:=
map
[
string
]
interface
{}{}
c
.
Request
.
ParseForm
()
for
k
,
v
:=
range
c
.
Request
.
PostForm
{
reqMap
[
k
]
=
v
[
0
]
}
res
,
_
:=
json
.
Marshal
(
data
)
req
,
_
:=
json
.
Marshal
(
reqMap
)
param
:=
map
[
string
]
interface
{}
{
"token"
:
token
,
"operate"
:
ApiMap
[
path
][
0
],
"module"
:
ApiMap
[
path
][
1
],
"path"
:
path
,
"method"
:
method
,
"req"
:
string
(
req
),
"res"
:
string
(
res
),
"type"
:
2
,
"ip"
:
ip
,
"opTime"
:
time
.
Now
()
.
Unix
(),
}
utils
.
Request
(
LogPushUrl
,
param
,
map
[
string
]
interface
{}{
"X-CA-STAGE"
:
XCaStage
,
},
"POST"
,
"form"
)
}
utils/utils.go
View file @
126b2bc1
...
...
@@ -7,9 +7,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"io/ioutil"
"math/rand"
"net/http"
"strconv"
"strings"
"time"
)
const
MessageHost
=
"http://pubdev.guangdianyun.tv"
...
...
@@ -116,4 +118,32 @@ func Reverse(s string) string {
func
GenUUID
()
string
{
u
,
_
:=
uuid
.
NewRandom
()
return
u
.
String
()
}
\ No newline at end of file
}
func
RandomCoupon
()
string
{
// 48 ~ 57 数字
// 65 ~ 90 A ~ Z
// 97 ~ 122 a ~ z
// 一共62个字符,在0~61进行随机,小于10时,在数字范围随机,
// 小于36在大写范围内随机,其他在小写范围随机
var
length
=
16
// 2个-
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
result
:=
make
([]
string
,
0
,
length
)
for
i
:=
0
;
i
<
length
;
i
++
{
if
i
>
0
&&
i
%
4
==
0
{
result
=
append
(
result
,
"-"
)
}
t
:=
rand
.
Intn
(
62
)
if
t
<
10
{
result
=
append
(
result
,
strconv
.
Itoa
(
rand
.
Intn
(
10
)))
}
else
if
t
<
36
{
// result = append(result, string(rand.Intn(26)+65))
result
=
append
(
result
,
string
(
rune
(
rand
.
Intn
(
26
)
+
65
)))
}
else
{
// result = append(result, string(rand.Intn(26)+97))
result
=
append
(
result
,
string
(
rune
(
rand
.
Intn
(
26
)
+
97
)))
}
}
return
strings
.
ToUpper
(
strings
.
Join
(
result
,
""
))
}
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