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分类目录归档:Golang-Dev
相当于验证用户上传的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 mod init example/hello
chf@chf:~/go_obj/test$ cat go.mod
module test_mod
go 1.23.2
go mod tidy
GO111MODULE开启或关闭模块支持 GO111MODULE=off 关闭模块支持,go 会从 GOPATH 和 vendor 文件夹寻找包。 GO111MODULE=on 开启模块支持,go 会忽略 GOPATH 和 vendo
安装位置自行选择当前是/usr/local/
tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz
您可以通过将以下行添加到 $HOME/.profile 或 /etc/profile(用于系统范围的安装):
export PATH=$PATH:/usr/local/go/bin
通过打开命令提示符并键入 Go 来验证是否已安装 Go 以下命令:
go version
gopdf gopdf is a simple library for generating PDF document written in Go lang.
A minimum version of Go 1.13 is required.
Features Unicode subfont embedding. (Chinese, Japanese, Korean, etc.) Draw line, oval, rect, curve Draw image ( jpg, png ) Set image mask Password protection Font kerning Install
github.com/xuri/excelize/v2
func (f *File) SetSheetCol(sheet, cell string, slice interface{}) error
根据给定的工作表名称、起始坐标和 slice 类型引用按列赋值。例如,在名为 Sheet1 的工作表 B 列上,以 B6 单元格作为起始坐标按列赋值:
err := f.SetSheetCol("Sheet1", "B6", &[]interface{}{"1&quopackage guitar
import (
"io"
"net/http"
"go-weixin/app/guitar/api/internal/logic/guitar"
"go-weixin/app/guitar/api/internal/svc"
"go-weixin/app/guitar/api/internal/types"
"go-weixin/common/utilpackage main
import (
"fmt"
"sync"
"time"
)
// 全局变量
var mp sync.Map
func syncGolbal() {
if v, exists := mp.Load("name"); exists {
fmt.Println(v)
} else {
mp.Store("name", "chf")
}
}
// 管道
1. 创建文件夹go-weixin-obj
bin, pkg, src
2. 在src中执行
git clone xxx
export GOPATH='/xxx/go-weixin-obj/'
export CGO_ENABLED='0'
version: "3.0"
services:
userrpc:
hostna