Forráskód Böngészése

Merge branch 'feature/change_log' of eta_server/eta_report into master

xyxie 1 éve
szülő
commit
e09bc8e6d0
3 módosított fájl, 90 hozzáadás és 17 törlés
  1. 1 0
      .gitignore
  2. 65 0
      utils/constants.go
  3. 24 17
      utils/logs.go

+ 1 - 0
.gitignore

@@ -1,4 +1,5 @@
 /rdlucklog
+/etalogs
 /.idea
 /binlog
 /*.exe

+ 65 - 0
utils/constants.go

@@ -1,9 +1,14 @@
 package utils
 
+const (
+	Md5Key = "Ks@h64WJ#tcVgG8$&WlNfqvLAtMgpxWN"
+)
+
 // 常量定义
 const (
 	FormatTime            = "15:04:05"                //时间格式
 	FormatDate            = "2006-01-02"              //日期格式
+	FormatDateUnSpace     = "20060102"                //日期格式
 	FormatDateTime        = "2006-01-02 15:04:05"     //完整时间格式
 	HlbFormatDateTime     = "2006-01-02_15:04:05.999" //完整时间格式
 	FormatDateTimeUnSpace = "20060102150405"          //完整时间格式
@@ -23,3 +28,63 @@ const (
 	RegularMobile = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(16[0-9])|(19[0-9]))\\d{8}$" //手机号码
 	RegularEmail  = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`                                             //匹配电子邮箱
 )
+
+// 验证码code
+const (
+	REGISTER_CODE = iota + 1 //注册
+	LOGIN_CODE               //登录
+)
+
+// 聚合短信
+var (
+	JhGnTplId = "65692" //聚合国内模板编码
+	JhGjTplId = "10054" //聚合国内模板编码
+
+	JhGnAppKey = "4c8504c49dd335e99cfd7b6a3a9e2415" //聚合国内AppKey
+	JhGjAppKey = "3326ad2c1047a4cd92ace153e6044ca3"
+)
+
+// 科大讯飞--语音合成
+const (
+	XfSTATUS_FIRST_FRAME    = 0 //第一帧标识
+	XfSTATUS_CONTINUE_FRAME = 1 //中间帧标识
+	XfSTATUS_LAST_FRAME     = 2 //最后一帧标识
+	XfAPPID                 = "5ed70e9d"
+	XfAPIKey                = "d580509ca262e9586fb65a7064d5ce77"
+	XfAPISecret             = "a085720dc55850c720fa5576335f847a"
+	XfHostUrl               = "wss://tts-api.xfyun.cn/v2/tts"
+	XfOrigin                = "http://tts-api.xfyun.cn/"
+	XfHost                  = "tts-api.xfyun.cn"
+)
+
+// OSS
+var (
+	Endpoint   string = "oss-cn-shanghai.aliyuncs.com"
+	Bucketname string = "hongze"
+
+	Imghost          string = "http://hongze.oss-cn-shanghai.aliyuncs.com/"
+	Upload_dir       string = "static/images/"
+	Upload_Audio_Dir string = "static/audio/"
+
+	AccessKeyId     string = "LTAIFMZYQhS2BTvW"
+	AccessKeySecret string = "12kk1ptCHoGWedhBnKRVW5hRJzq9Fq"
+)
+
+// 客户状态
+const (
+	COMPANY_STATUS_TRY_OUT   = "试用"
+	COMPANY_STATUS_FOREVER   = "永续"
+	COMPANY_STATUS_FREEZE    = "冻结"
+	COMPANY_STATUS_LOSE      = "流失"
+	COMPANY_STATUS_FORMAL    = "正式"
+	COMPANY_STATUS_POTENTIAL = "潜在"
+)
+
+// 缓存key
+const (
+	CACHE_KEY_USER_VIEW = "user_view_record" //用户阅读数据
+)
+
+const (
+	key = "KcSJaJoUBC2ZAA7HEWpaiH49" //全局加密KEY
+)

+ 24 - 17
utils/logs.go

@@ -2,17 +2,19 @@ package utils
 
 import (
 	"encoding/json"
+	"fmt"
 	"github.com/beego/beego/v2/core/logs"
 	"github.com/sirupsen/logrus"
 	"gopkg.in/natefinch/lumberjack.v2"
 	"os"
 	"path"
+	"time"
 )
 
 const (
-	DefaultLogPath    = "./rdlucklog"
-	DefaultBinlogPath = "./binlog"
-	DefaultBinlogFile = "binlog.log"
+	DefaultLogPath    = "./etalogs/filelog"
+	DefaultBinlogPath = "./etalogs/binlog"
+	DefaultApiLogPath = "./etalogs/apilog"
 )
 
 var FileLog = logrus.New()
@@ -26,14 +28,16 @@ func init() {
 	}
 	logFile := LogFile
 	if logFile == "" {
-		logFile = "eta_report.log"
+		logFile = fmt.Sprintf("%s.log", time.Now().Format(FormatDateUnSpace))
 	}
 	os.MkdirAll(logPath, os.ModePerm)
 
 	// 打开文件
 	logFileName := path.Join(logPath, logFile)
+	logConf := getDefaultLogrusConfig(logFileName)
+	logConf.MaxAge = 1
 	// 使用滚动压缩方式记录日志
-	rolling(FileLog, logFileName)
+	rolling(FileLog, logConf)
 	//rolling(bLogFileName)
 	// 设置日志输出JSON格式
 	jsonFormat := new(logrus.JSONFormatter)
@@ -45,6 +49,7 @@ func init() {
 	// 设置日志记录级别
 	//FileLog.SetLevel(logrus.DebugLevel)
 
+	//初始化binlog日志
 	//FileLog.Info("abc")
 	initBinlog()
 	initApiLog()
@@ -71,7 +76,7 @@ func initBinlog() {
 	}
 	binlogFile := BinLogFile
 	if binlogFile == "" {
-		binlogFile = DefaultBinlogFile
+		binlogFile = fmt.Sprintf("%s.log", time.Now().Format(FormatDateUnSpace))
 	}
 	os.MkdirAll(binlogPath, os.ModePerm)
 	logFileName := path.Join(binlogPath, binlogFile)
@@ -89,22 +94,19 @@ func initBinlog() {
 func initApiLog() {
 	logPath := ApiLogPath
 	if logPath == "" {
-		if RunMode == "release" {
-			logPath = `/data/etalogs/eta_report`
-		} else {
-			logPath = `./rdlucklog/api`
-		}
+		logPath = DefaultApiLogPath
 	}
 	logFile := ApiLogFile
 	if logFile == "" {
-		logFile = "eta_report_api.log"
+		logFile = fmt.Sprintf("%s.log", time.Now().Format(FormatDateUnSpace))
 	}
 	os.MkdirAll(logPath, os.ModePerm)
 
 	// 打开文件
 	logFileName := path.Join(logPath, logFile)
+	logConf := getDefaultLogrusConfig(logFileName)
 	// 使用滚动压缩方式记录日志
-	rolling(ApiLog, logFileName)
+	rolling(ApiLog, logConf)
 	//rolling(bLogFileName)
 	// 设置日志输出JSON格式
 	jsonFormat := new(logrus.JSONFormatter)
@@ -114,16 +116,21 @@ func initApiLog() {
 }
 
 // 日志滚动设置
-func rolling(fLog *logrus.Logger, logFile string) {
+func rolling(fLog *logrus.Logger, config *lumberjack.Logger) {
 	// 设置输出
-	fLog.SetOutput(&lumberjack.Logger{
+	fLog.SetOutput(config)
+}
+
+func getDefaultLogrusConfig(logFile string) (config *lumberjack.Logger) {
+	config = &lumberjack.Logger{
 		Filename:   logFile, //日志文件位置
-		MaxSize:    100,     // 单文件最大容量,单位是MB
+		MaxSize:    256,     // 单文件最大容量,单位是MB
 		MaxBackups: 3,       // 最大保留过期文件个数
 		MaxAge:     7,       // 保留过期文件的最大时间间隔,单位是天
 		Compress:   true,    // 是否需要压缩滚动日志, 使用的 gzip 压缩
 		LocalTime:  true,
-	})
+	}
+	return
 }
 
 func getDefaultLogConfig() logConfig {