zoukankan      html  css  js  c++  java
  • gin 安装

    Gin安装

    1.在系统环境变量中 GOROOT 值为 C:Go ,并保存

    2.将GOROOT 添加到环境变量中,并保存

    3.使用 mod

    # 初始化 mod
    go mod init 项目名称
    # 指定gin的版本
    go mod edit -require github.com/gin-gonic/gin@latest
    # 开启模块支持
    go env -w GO111MODULE=on
    # 添加国内代理
    go env -w GOPROXY=https://goproxy.cn,direct
    

    4.安装 gin 框架

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

    5.简单的示例, 源代码必须在新建的src目录中

    package main
    
    import "github.com/gin-gonic/gin"
    
    func main() {
    	r := gin.Default()
    	r.GET("/ping", func(c *gin.Context) {
    		c.JSON(200, gin.H{
    			"message": "pong",
    		})
    	})
    	r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
    }
    

    6.运行代码

    go run example.go
    
     
  • 相关阅读:
    迭代器概念与traits编程技法
    C++模板的特化与偏特化
    c++ operator关键字
    cookie-小总结吧
    ping
    git
    setTimeout()基础/setInterval()基础
    SASS
    命令行编译sass
    sublime添加sass编译
  • 原文地址:https://www.cnblogs.com/xiaoyuya/p/14856173.html
Copyright © 2011-2022 走看看