123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package utils
- import (
- "os"
- "qfw/util"
- "qfw/util/redis"
- "time"
- log "github.com/sirupsen/logrus"
- )
- type JSON map[string]interface{}
- const (
- REDISDB = "jyqyfw"
- CODE_TOKEN_EXPIRE = 1000 //token过期
- MSG_TOKEN_EXPIRE = "token已过期"
- CODE_E1 = 1001
- MSG_E1 = "token错误"
- CODE_E2 = 1002
- MSG_E2 = "参数错误"
- CODE_E3 = 1003
- MSG_E3 = "调用次数过超限制"
- CODE_E4 = 1004
- MSG_E4 = "服务过期"
- CODE_E5 = 1005
- MSG_E5 = "服务条数过超限制"
- CODE_ERR_E0 = 4000
- MSG_ERR_E = "内部错误"
- CODE_ERR_E1 = 4001
- CODE_ERR_E2 = 4002
- CODE_ERR_E3 = 4003
- CODE_ERR_E4 = 4004
- //------
- // CODE_OUTTIME = 0
- // MSG_OUTTIME = "不在服务时间(服务时间06:00-23:00)"
- CODE_SUCCESS = 1
- MSG_SUCCESS = "请求成功"
- )
- var (
- Sysconfig map[string]interface{}
- A map[string]interface{}
- B map[string]interface{}
- )
- func init() {
- //初始化日志
- util.ReadConfig(&Sysconfig)
- t := &log.TextFormatter{}
- t.TimestampFormat = "01-02 15:04:05.000"
- t.ForceColors = true
- t.DisableTimestamp = false
- t.FullTimestamp = true
- log.SetFormatter(t)
- log.SetOutput(os.Stdout)
- log.SetLevel(log.Level(util.IntAllDef(Sysconfig["loglevel"], 5)))
- //
- plan, _ := Sysconfig["plan"].(map[string]interface{})
- A = plan["A"].(map[string]interface{})
- B = plan["B"].(map[string]interface{})
- initmongo()
- redisconf := Sysconfig["redis"].(map[string]interface{})
- redis.InitRedisBySize(util.ObjToString(redisconf["addr"]), util.IntAllDef(redisconf["pool"], 10), 20, 240)
- log.Info("Util init over...")
- initrsa()
- }
- func GetDayMinMax(t time.Time) (int64, int64) {
- min := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local).Unix()
- return min, min + 86400
- }
- func DesZero() int {
- t := time.Now()
- d := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, time.Local).Unix()
- return int(d - t.Unix())
- }
|