global.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package global
  2. import (
  3. "github.com/redis/go-redis/v9"
  4. "github.com/songzhibin97/gkit/cache/local_cache"
  5. "go.uber.org/zap"
  6. "golang.org/x/sync/singleflight"
  7. "gorm.io/gorm"
  8. "lc-fangdaosha/config"
  9. "time"
  10. )
  11. var (
  12. Db *gorm.DB
  13. GVA_REDIS *redis.Client
  14. BlackCache local_cache.Cache
  15. GVA_LOG *zap.Logger
  16. Config = config.Config
  17. GVA_Concurrency_Control = &singleflight.Group{}
  18. )
  19. type GVA_MODEL struct {
  20. ID uint `gorm:"primarykey"` // 主键ID
  21. CreatedAt time.Time // 创建时间
  22. UpdatedAt time.Time // 更新时间
  23. DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // 删除时间
  24. }
  25. type DateTimeString time.Time
  26. const DateTimeFormatCN = "2006-01-02 15:04:05"
  27. func (t *DateTimeString) UnmarshalJSON(data []byte) (err error) {
  28. now, err := time.ParseInLocation(`"`+DateTimeFormatCN+`"`, string(data), time.Local)
  29. *t = DateTimeString(now)
  30. return
  31. }
  32. func (t *DateTimeString) MarshalJSON() ([]byte, error) {
  33. b := make([]byte, 0, len(DateTimeFormatCN)+2)
  34. b = append(b, '"')
  35. b = time.Time(*t).AppendFormat(b, DateTimeFormatCN)
  36. b = append(b, '"')
  37. return b, nil
  38. }