errors_here.go 635 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package utils
  2. import (
  3. "crypto/rsa"
  4. "crypto/x509"
  5. "github.com/gin-gonic/gin"
  6. "math/rand"
  7. "net/http"
  8. "time"
  9. )
  10. type TimeType = time.Time
  11. func TimeNow() TimeType {
  12. return time.Now()
  13. }
  14. func Sleep(sec int) {
  15. time.Sleep(time.Duration(sec) * time.Second)
  16. }
  17. func RandInt(n int) int {
  18. return rand.Intn(n)
  19. }
  20. func MarshalPublicKey(key *rsa.PublicKey) ([]byte, error) {
  21. return x509.MarshalPKIXPublicKey(key)
  22. }
  23. func ErrorHandler(ctx *gin.Context) {
  24. defer func() {
  25. if recover() != nil {
  26. ctx.JSON(HttpError, Fail("oops! Something bad happened."))
  27. }
  28. }()
  29. ctx.Next()
  30. }
  31. func CheckOrigin(r *http.Request) bool {
  32. return true
  33. }