Commit 1ebe242b by zhengqiuyun86

mysql加入连接配置

parent 61b53bee
......@@ -58,6 +58,7 @@ var LogLevel = "DEBUG"
var LogColorful = true
var LogResponseLength int
var LogShowSql = true
var LogIndexNamePrefix = ""
//Redis conf
type RedisConf struct {
......
......@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/log"
"git.168cad.top/zhengqiuyun/rym-util/util"
......@@ -13,7 +14,11 @@ import (
)
func getCurrentIndex() string {
return indexNamePrefix + util.FormatDates(time.Now())
if conf.LogIndexNamePrefix == "" {
return indexNamePrefix + util.FormatDates(time.Now())
} else {
return conf.LogIndexNamePrefix + util.FormatDates(time.Now())
}
}
type ServerLogModel struct {
......
package getWay
import (
"git.168cad.top/zhengqiuyun/rym-util/util"
"github.com/gin-gonic/gin"
)
const headerKeyToken = "token"
const headerKeyPlatformCode = "platform"
const (
headerKeyToken = "token"
headerKeyPlatform = "platform"
headerKeyAppId = "appId"
headerKeyTimeStamp = "timeStamp"
headerKeySign = "sign"
)
const headerKeyClientSource = "clientSource"
func getHeader(c *gin.Context, key string) string {
v := c.GetHeader(key)
return v
}
func GetToken(c *gin.Context) string {
return getHeader(c, headerKeyToken)
return c.GetHeader(headerKeyToken)
}
func SetToken(v string, c *gin.Context) {
c.Header(headerKeyToken, v)
}
func GetPlatformCode(c *gin.Context) string {
platformCode := getHeader(c, headerKeyPlatformCode)
func GetAppId(c *gin.Context) string {
return c.GetHeader(headerKeyAppId)
}
func GetTimeStamp(c *gin.Context) string {
return c.GetHeader(headerKeyTimeStamp)
}
func GetSign(c *gin.Context) string {
return c.GetHeader(headerKeySign)
}
func GetPlatform(c *gin.Context) string {
platformCode := c.GetHeader(headerKeyPlatform)
return platformCode
}
func GetClientSource(c *gin.Context) string {
platformCode := getHeader(c, headerKeyClientSource)
return platformCode
h := c.GetHeader(headerKeyClientSource)
if h == "" {
return util.GetInterfaceToString(clientSource{
AppId: GetAppId(c),
TimeStamp: GetTimeStamp(c),
Sign: GetSign(c),
Platform: GetPlatform(c),
})
}
return h
}
type clientSource struct {
AppId string `json:"appId"`
TimeStamp string `json:"timeStamp"`
Sign string `json:"sign"`
Platform string `json:"platform"`
}
......@@ -116,15 +116,3 @@ func GetStartTime(c *gin.Context) int64 {
func logStart(c *gin.Context) {
log.Info(fmt.Sprintf("开始 %s %s %s %s", GetMethod(c), GetURL(c), GetToken(c), GetClientIP(c)))
}
func GetAppId(c *gin.Context) string {
return c.GetHeader("appId")
}
func GetTimeStamp(c *gin.Context) string {
return c.GetHeader("timeStamp")
}
func GetSign(c *gin.Context) string {
return c.GetHeader("sign")
}
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 to comment