package utils import ( "fmt" "strings" "time" "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 GetMonthFromDate(date string) (int) { if date == "" { return -1 } array := strings.Split(date, " ") if len(array) == 0 { return -1 } date = array[0] t, err := time.ParseInLocation("2006-01-02", date, time.Local) if err != nil { return -1 } return int(t.Month()) }