global.go 1.1 KB

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