分类目录归档:Golang-Dev

[ 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 >

[ golang创建环境 ]


golang创建环境-点击跳转官方文档

在当前文件夹下创建依赖跟踪mod

go mod init example/hello

chf@chf:~/go_obj/test$ cat go.mod

module test_mod

go 1.23.2

自动根据当前文件夹下使用到的模块,下载并且添加到mod里面

go mod tidy

配置mod使用关系

GO111MODULE开启或关闭模块支持 GO111MODULE=off 关闭模块支持,go 会从 GOPATH 和 vendor 文件夹寻找包。 GO111MODULE=on 开启模块支持,go 会忽略 GOPATH 和 vendo

< Read more >

[ golang安装 ]


golang下载安装-点击跳转官方文档

下载地址

Linux中安装

安装位置自行选择当前是/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

< Read more >

[ go使用pdf ]


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

< Read more >

[ golang使用excel ]


golang中使用excel并使用http返回

下载

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&quo

< Read more >

[ go-zero实战项目部署完整版 ]


go-zero微服务docker-compose部署完整版

演示git项目地址

一.前置条件

1. 安装go

2. git拉取代码

1. 创建文件夹go-weixin-obj
bin, pkg, src

2. 在src中执行
git clone xxx

3. 环境变量

export GOPATH='/xxx/go-weixin-obj/'

export CGO_ENABLED='0'

二.开始部署

1.docker-compose.yml

version: "3.0"
services:
  userrpc:
    hostna

< Read more >