本文目的是一個地方,學會完整的全棧開發,搞定後端部分, 後續若是反響好,會吧把前端部分也補充前端
當前版本: 1.13.4linux
主意go 1.13之後官方默認支持模塊方式,因此咱們不在介紹哦以前的使用GOPATH的方式. 擁抱模塊吧.git
下載安裝包 dl.google.com/go/go1.13.4… -若是是windows系統建議下載virtualbox 虛擬機在按照github
wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
tar -zxvf go1.9.2.linux-amd64.tar.gz
mv go/ /usr/local/
複製代碼
配置 /etc/profile
vi /etc/profile
添加環境變量GOROOT和將GOBIN添加到PATH中
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
複製代碼
配置完畢後,執行命令令其生效golang
source /etc/profile
複製代碼
在控制檯輸入go version,若輸出版本號則安裝成功ubuntu
執行 go help命令查看幫助windows
go help ✔ 10109 20:09:08
Go is a tool for managing Go source code.
Usage:
go <command> [arguments]
The commands are:
bug start a bug report
build compile packages and dependencies
clean remove object files and cached files
doc show documentation for package or symbol
env print Go environment information
fix update packages to use new APIs
fmt gofmt (reformat) package sources
generate generate Go files by processing source
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages or modules
mod module maintenance
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet report likely mistakes in packages
Use "go help <command>" for more information about a command.
複製代碼
請不要太在乎模塊. 慢慢的你就會理解.後端
在命令行下執行安裝bash
go get -u github.com/gin-gonic/gin
檢查/usr/local/go/path中是否存在gin的代碼包
複製代碼
編寫一個test.go文件curl
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
}
複製代碼
執行test.go
go run test.go
複製代碼
curl 127.0.0.1:8080/ping
複製代碼
至此,咱們的環境安裝都基本完成了 :)
上面只是一個Gin的小Demo .感覺一下從無到個哦按照開發