Commit 126b2bc1 by swh

log

parent 1b1b9a55
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")
}
......@@ -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, ""))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment