![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
go
八点博客(钏)
专注分享技术交流
展开
-
go/gin:使用redis
"github.com/go-redis/redis"1、安装go get -u github.com/go-redis/redis2、引入并初始化var ( Redis *redis.Client)func InitRedis() (err error) { Redis = redis.NewClient(&redis.Options{ Addr: "127.0.0.1:6379", Password: "", // no password se.原创 2021-01-21 16:08:37 · 1376 阅读 · 0 评论 -
go/gin使用bcrypt
1、加密result,_ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)2、比对密码bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password))原创 2021-01-12 16:29:59 · 343 阅读 · 0 评论 -
go/gin使用jwt
1、安装拓展包$ go get -u github.com/dgrijalva/jwt-go2、发放tokenfunc ReleaseToken(user *model.User) (tokenString string,err error) { expire := time.Now().Add(7 * 24 * time.Hour) claims := &Claims{ UserId: user.ID, StandardClaims: jwt.StandardClaim原创 2021-01-12 16:09:51 · 699 阅读 · 0 评论 -
linux部署go/gin项目
安装部署go环境1、打开go官网(https://golang.google.cn/dl/),找到适合系统的版本(uname -a查看版本),复制下载连接,比如https://golang.google.cn/dl/go1.15.6.linux-amd64.tar.gz2、下载$ wget https://golang.google.cn/dl/go1.15.6.linux-amd64.tar.gz3、解压$ tar xzf go1.15.6.linux-amd64.tar....原创 2021-01-04 12:17:57 · 1613 阅读 · 5 评论 -
Go/Gin 项目封装拆分步骤
原始项目package mainimport( "github.com/gin-gonic/gin" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/mysql")type Todo struct{ ID int `json:"id"` Title string `json:"title"` Status bool `json:"status"`}var( DB *gorm.DB)f原创 2020-12-30 12:06:04 · 1249 阅读 · 0 评论 -
Go/Gin报错集锦(1):exec: “gcc“: executable file not found in %PATH%
1、下载https://jmeubank.github.io/tdm-gcc/download/2、全部勾选,完成3、命令行输入 gcc -v4、重启goland原创 2020-12-29 17:34:14 · 175 阅读 · 0 评论 -
Go/Gin 数据库相关
1、安装gormgo get -u gorm.io/gormgo get -u gorm.io/driver/mysql2、引入import ( "gorm.io/gorm" "gorm.io/driver/sqlite")3、连接func main() { dsn := "root:root678@tcp(127.0.0.1:3306)/topics?charset=utf8mb4&parseTime=True&loc=Local" db, _原创 2020-09-27 10:35:22 · 205 阅读 · 0 评论 -
GO/Gin 使用自定义验证器 V8 V10
使用V8版本package main import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "gopkg.in/go-playground/validator.v8" "net/http" "reflect" "time") //binding 绑定一些验证请求参数,自定义标签bookabledate表示可预约的时期type Booking struct { CheckIn time.T原创 2020-09-26 10:43:35 · 1828 阅读 · 3 评论 -
Go:Beego安装与使用
由于下载过慢,改用代理1、配置代理go env -w GO111MODULE=ongo env -w GOPROXY=https://goproxy.io,direct2、安装 beegogo get -u github.com/astaxie/beego3、安装bee脚手架go get -u github.com/beego/bee4、创建项目bee new test5、运行项目bee runbeego采用mvc,使用方法和大多数mvc框架差不多,不原创 2020-09-23 16:50:00 · 488 阅读 · 0 评论