utils.go 579 B

12345678910111213141516171819202122232425262728
  1. package utils
  2. import (
  3. "fmt"
  4. "regexp"
  5. "unsafe"
  6. "encoding/json"
  7. )
  8. // StrToBytes 快读的string转byte
  9. func StrToBytes(s string) []byte {
  10. x := (*[2]uintptr)(unsafe.Pointer(&s))
  11. h := [3]uintptr{x[0], x[1], x[1]}
  12. return *(*[]byte)(unsafe.Pointer(&h))
  13. }
  14. func PrintStruct(prefix string, data interface{}) {
  15. bytes, _ := json.Marshal(data)
  16. fmt.Printf("%s, %s\n", prefix, bytes)
  17. }
  18. func VerifyEmailFormat(email string) bool {
  19. pattern := `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*` //匹配电子邮箱
  20. reg := regexp.MustCompile(pattern)
  21. return reg.MatchString(email)
  22. }