utils.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package utils
  2. import (
  3. "os"
  4. "qfw/util"
  5. "qfw/util/redis"
  6. "time"
  7. log "github.com/sirupsen/logrus"
  8. )
  9. type JSON map[string]interface{}
  10. const (
  11. REDISDB = "jyqyfw"
  12. CODE_TOKEN_EXPIRE = 1000 //token过期
  13. MSG_TOKEN_EXPIRE = "token已过期"
  14. CODE_E1 = 1001
  15. MSG_E1 = "token错误"
  16. CODE_E2 = 1002
  17. MSG_E2 = "参数错误"
  18. CODE_E3 = 1003
  19. MSG_E3 = "调用次数过超限制"
  20. CODE_E4 = 1004
  21. MSG_E4 = "服务过期"
  22. CODE_E5 = 1005
  23. MSG_E5 = "服务条数过超限制"
  24. CODE_ERR_E0 = 4000
  25. MSG_ERR_E = "内部错误"
  26. CODE_ERR_E1 = 4001
  27. CODE_ERR_E2 = 4002
  28. CODE_ERR_E3 = 4003
  29. CODE_ERR_E4 = 4004
  30. //------
  31. // CODE_OUTTIME = 0
  32. // MSG_OUTTIME = "不在服务时间(服务时间06:00-23:00)"
  33. CODE_SUCCESS = 1
  34. MSG_SUCCESS = "请求成功"
  35. )
  36. var (
  37. Sysconfig map[string]interface{}
  38. A map[string]interface{}
  39. B map[string]interface{}
  40. )
  41. func init() {
  42. //初始化日志
  43. util.ReadConfig(&Sysconfig)
  44. t := &log.TextFormatter{}
  45. t.TimestampFormat = "01-02 15:04:05.000"
  46. t.ForceColors = true
  47. t.DisableTimestamp = false
  48. t.FullTimestamp = true
  49. log.SetFormatter(t)
  50. log.SetOutput(os.Stdout)
  51. log.SetLevel(log.Level(util.IntAllDef(Sysconfig["loglevel"], 5)))
  52. //
  53. plan, _ := Sysconfig["plan"].(map[string]interface{})
  54. A = plan["A"].(map[string]interface{})
  55. B = plan["B"].(map[string]interface{})
  56. initmongo()
  57. redisconf := Sysconfig["redis"].(map[string]interface{})
  58. redis.InitRedisBySize(util.ObjToString(redisconf["addr"]), util.IntAllDef(redisconf["pool"], 10), 20, 240)
  59. log.Info("Util init over...")
  60. initrsa()
  61. }
  62. func GetDayMinMax(t time.Time) (int64, int64) {
  63. min := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local).Unix()
  64. return min, min + 86400
  65. }
  66. func DesZero() int {
  67. t := time.Now()
  68. d := time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, time.Local).Unix()
  69. return int(d - t.Unix())
  70. }