utils.go 1.03 KB
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")
}