12345678910111213141516171819202122232425262728 |
- package utils
- import (
- "fmt"
- "regexp"
- "unsafe"
- "encoding/json"
- )
- // StrToBytes 快读的string转byte
- func StrToBytes(s string) []byte {
- x := (*[2]uintptr)(unsafe.Pointer(&s))
- h := [3]uintptr{x[0], x[1], x[1]}
- return *(*[]byte)(unsafe.Pointer(&h))
- }
- func PrintStruct(prefix string, data interface{}) {
- bytes, _ := json.Marshal(data)
- fmt.Printf("%s, %s\n", prefix, bytes)
- }
- func VerifyEmailFormat(email string) bool {
- pattern := `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*` //匹配电子邮箱
- reg := regexp.MustCompile(pattern)
- return reg.MatchString(email)
- }
|