utils.go
906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package utils
import (
"encoding/base64"
"net/http"
"github.com/meiqia/chi/render"
"time"
"regexp"
)
func BindJSON(r *http.Request, obj interface{}) error {
if err := render.Bind(r.Body, obj); err != nil {
return err
}
return structValidator.ValidateStruct(obj)
}
func JudgeBase64(str string) bool {
_, err := base64.StdEncoding.DecodeString(str)
return err == nil
}
//判断参数时间距离当前时间的小时数,时间戳
func GetHourTimeToNow(timeInt int64)int64{
return (time.Now().Unix()-timeInt)/3600
}
//判断参数时间是否为当前天。坑:go时间原点(诞生日): 2006-01-02 15:04:05
func GetDayTiemToNow(timeInt int64)bool{
Now:=time.Unix(time.Now().Unix(),0)
timee:=time.Unix(timeInt,0)
return Now.Format("2006-01-02")==timee.Format("2006-01-02")
}
func CheckParam(str string)bool{
res, _ := regexp.MatchString("^[0-9a-zA-Z]{6}$", str)
return res
}