golang验证结构体
相当于验证用户上传的json参数
定义结构
package dto
type TestJsonReq struct {
Name string `json:"name" binding:"min=3,max=20,required"`
Password string `json:"password" binding:"required"`
Age int `json:"age" binding:"required分类标签归档:gin
相当于验证用户上传的json参数
定义结构
package dto
type TestJsonReq struct {
Name string `json:"name" binding:"min=3,max=20,required"`
Password string `json:"password" binding:"required"`
Age int `json:"age" binding:"requiredpackage collections
import (
"crypto/sha256"
"encoding/base64"
"fmt"
"strconv"
"strings"
"math/rand"
"golang.org/x/crypto/pbkdf2"
)
const Iterations inpackage collections
import (
"fmt"
"time"
"github.com/golang-jwt/jwt/v5"
)
var hmacSampleSecret = []byte("my_eyjwt_secret")
type TokenMap struct {
Type string
Nbf int64
Username string
UserId int
Exp go get -u "github.com/gin-gonic/gin"
go run main.go
github.com/gin-gonic/gin轻量级web框架gorm.io/gorm数据库第三方包gopkg.in/yaml.v3 读取yaml配置文件github.com/sirupsen/logrus 日志配置github.com/satori/go.uuid 生成uuid