util.go 494 B

123456789101112131415161718192021222324252627282930
  1. package util
  2. import (
  3. "app.yhyue.com/moapp/jybase/encrypt"
  4. "math/rand"
  5. "time"
  6. )
  7. var Date_Full_Layout = "2006-01-02 15:04:05"
  8. // 加密
  9. func EncodeId(sid string) string {
  10. if sid == "" {
  11. return ""
  12. }
  13. return encrypt.EncodeArticleId2ByCheck(sid)
  14. }
  15. // 解密
  16. func DecodeId(eid string) string {
  17. if eid == "" {
  18. return ""
  19. }
  20. return encrypt.DecodeArticleId2ByCheck(eid)[0]
  21. }
  22. func GetRand(n int) int {
  23. randGen := rand.New(rand.NewSource(time.Now().UnixNano()))
  24. return randGen.Intn(n)
  25. }