分类标签归档:gin

[ gin验证请求参数 ]


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

< Read more >

[ gin使用jwt ]


主要使用jwt/v5框架

package 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 

< Read more >

[ Gin框架使用 ]


基本使用

安装(提前配置好gopath环境变量, mod包管理)

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
  • ...等待补充

二.响应

  • 使用"-"来隐藏此属性的响应, 防

< Read more >