go环境配置

风之舞 2024-03-21 15:45:36 103
简介: go环境配置

安装 go gin
go env -w GO111MODULE=auto
go env -w GOPROXY=https://goproxy.cn,direct

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

创建  %GOPATH%/src/golang.org/x/
cd   %GOPATH%/src/golang.org/x/
git   clone git@github.com:golang/net|crypto|sync|text.git
创建  %GOPATH%/src/google.golang.org
git clone https://github.com/protocolbuffers/protobuf-go.git 重命名 protobuf

主文件代码:
main.go
package main

import (
    "github.com/gin-gonic/gin"
    "net/http"
)

func main() {
    router := gin.Default()
    router.GET("/", func(c *gin.Context) {
        c.String(http.StatusOK, "Hello World")
    })
    router.Run(":8000")
}

![](http://blog.breezedance.com/uploads/app/images/img/h1/h1/img202403211548440_info265X359.png)