Commit 1ebe242b by zhengqiuyun86

mysql加入连接配置

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