Linux安装GoLang

  1. 作者QQ:67065435 QQ群:821635552

  2. 本站内容全部为作者原创,转载请注明出处!

安装GoLang

  1. 下载解压安装

    cd /root
    wget https://dl.google.com/go/go1.14.1.linux-amd64.tar.gz
    tar -zxvf go1.14.1.linux-amd64.tar.gz
    mv /root/go /usr/local/go
    
  2. 加入环境变量

    vim /etc/profile
    
    export PATH=$PATH:/usr/local/go/bin
    
    ESC
    :wq
    
    source /etc/profile
    
  3. 目录权限

    chown -R www:www /usr/local/go
    
  4. 测试是否安装成功

    su www
    go env
    

使用框架Gin

  1. 准备工作

    su www
    go env|grep GOPATH
    # 显示 GOPATH="/home/www/go"
    
    mkdir /home/www/go/src/golang.org/x
    cd /home/www/go/src/golang.org/x
    
    git clone https://github.com/golang/sys.git
    git clone https://github.com/golang/net.git
    git clone https://github.com/golang/text.git
    git clone https://github.com/golang/lint.git
    git clone https://github.com/golang/tools.git
    git clone https://github.com/golang/crypto.git
    
  2. 获取框架

    su www
    mkdir /www
    cd /www
    go get -u github.com/gin-gonic/gin
    
  3. 使用框架

    //参考 https://github.com/gin-gonic/gin/blob/master/README.md
    package main
    
    import "github.com/gin-gonic/gin"
    
    func main() {
        route := gin.Default()
    
        route.GET("/", func(c *gin.Context) {
            c.JSON(200, gin.H{
                "code": 200,
                "data": [0]int{},
                "msg": "/",
            })
        })
    
        route.GET("/:path", func(c *gin.Context) {
            path := c.Param("path")
            c.JSON(200, gin.H{
                "code": 200,
                "data": [0]int{},
                "msg": path,
            })
        })
        route.Run("0.0.0.0:8000")
    }
    

参考链接

  1. 中文网站

  2. 官方网站

  3. 常用框架

Copyright © 豆包嘿嘿~ 2012-∞ 冀ICP备17033181号 all right reserved,powered by Gitbook修订: 2020-08-19 14:05:41

results matching ""

    No results matching ""