go 言語 gin フレームワークの使用
ジンをインストールする
-
ジンフレームワークをダウンロードする
go get -u github.com/gin-gonic/gin
エラー:
go get github.com/gin-gonic/gin: module github.com/gin-gonic/gin: Get "https://proxy.golang.org/github.com/gin-gonic/gin/@v/list": dial tcp 172.217.160.113:443: connectex: A connection attempt failed because the connected party di d not properly respond a
エラーの理由は、プロキシ サーバーを構成する必要があるためです。
解決する:
go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.io,direct
-
import "github.com/gin-gonic/gin"
package main import "github.com/gin-gonic/gin" func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "hello go !", }) }) // r.Run() // 默认为localhost:8080 r.Run(":8089") // 修改为8089 }
テスト
http://localhost:8089/ にアクセスすると、結果は次のようになります。