Golang安装
-
安装
brew install go
-
配置
mkdir ~/go echo 'export PATH="/usr/local/opt/go/bin:$PATH"' >> ~/.zshrc echo 'export GOROOT="/usr/local/opt/go/libexec"' >> ~/.zshrc echo 'export GOPATH="$HOME/go"' >> ~/.zshrc source ~/.zshrc
IntelliJ IDEA安装
IntelliJ IDEA插件安装
-
安装
-
配置
在安装Go的过程中已经配置好GOROOT和GOPATH,IDE会自动识别,所以不用另行配置。
项目安装
-
新建项目
-
安装测试包
cd ~/IdeaProjects/go-test go mod init go-test go get github.com/labstack/echo/v4
-
创建测试文件
cd ~/IdeaProjects/go-test touch main.go
-
测试文件内容
package main import ( "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "net/http" ) func main() { // Echo instance e := echo.New() // Middleware e.Use(middleware.Logger()) e.Use(middleware.Recover()) // Routes e.GET("/", hello) // Start server e.Logger.Fatal(e.Start(":8080")) } // Handler func hello(c echo.Context) error { return c.String(http.StatusOK, "Hello, World!") }
-
运行测试文件
-
验证运行结果