utils.go 906 Bytes
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
}