gin go 更新缓存_【One by one系列】一步步学习Golang web框架Gin

35504e4c03d9d70615a898bee174266e.png

一步步学习Golang web框架Gin

建立项目

go mod 管理依赖

cd $gopathsrcgithub.comcarfieldWebapi

go mod init 如果不是在gopath下,其实也是提倡不在gopath下做开发,

go mod init后需要跟具体路径

go mod init github.comcarfieldWebapi
go get -u github.com/gin-gonic/gin

就可以看到在srchttp://github.comcarfieldWebapi 生成了go.mod文件

module github.com/carfield

go 1.13

下载gin包

go get -u github.com/gin-gonic/gin

ps:由于众所周知的原因,大概率是下不动,所以请修改代理

修改代理

go env -w GOPROXY=https://goproxy.cn,direct

再次执行

go get -u github.com/gin-gonic/gin

再次打开go.mod文件

module github.com/carfield

go 1.13

require (
 github.com/gin-gonic/gin v1.5.0 // indirect
 github.com/go-playground/universal-translator v0.17.0 // indirect
 github.com/go-sql-driver/mysql v1.5.0 // indirect
 github.com/json-iterator/go v1.1.9 // indirect
 github.com/leodido/go-urn v1.2.0 // indirect
 github.com/mattn/go-isatty v0.0.11 // indirect
 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 github.com/modern-go/reflect2 v1.0.1 // indirect
 golang.org/x/sys v0.0.0-20200117145432-59e60aa80a0c // indirect
 gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
 gopkg.in/yaml.v2 v2.2.7 // indirect
)

  • module定义包名
  • require用来定义依赖包及版本
  • indirect表示间接引用

快速开始

import "github.com/gin-gonic/gin"

package main

import (
 "net/http"

 "github.com/gin-gonic/gin" 
)

func main() {
 r := gin.Default()
 r.GET("/", func(c *gin.Context) {
  c.JSON(http.StatusOK, gin.H{
   "message": "hello,go-gin wholeheartedly at your service",
  })
 })

 
 r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}


作者:Garfield

同步更新至个人博客:Garfield-加菲的博客

本文版权归作者所有,未经许可禁止转载,否则保留追究法律责任的权利,若有需要请联系287572291@qq.com


588936281a312b6ab3a0ef5bb14bbc91.png
扫一扫,关注微信公众号
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值