utils.go
1.03 KB
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
41
package utils
import (
"encoding/base64"
"net/http"
"github.com/meiqia/chi/render"
"time"
"log"
)
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
}
//判断参数时间是距离当前时间是否达到给定分钟数的值
func CheckMinTiemToNow(timeInt int64,timeInterval int64)bool{
log.Println("time:",(time.Now().Unix()-timeInt)/60,timeInterval)
return (time.Now().Unix()-timeInt)/60<timeInterval
}
//判断参数时间是否为当前天。坑: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")
}