Featured image of post Go 课程

Go 课程

Go 并行计算的核心-Goroutine

Go 中比较核心的概念:协程(Coroutine),在 Go 中被改写之后称之为:Goroutine,它是并发模型的基本执行单元。事实上每一个Go程序至少有一个Goroutine:主Goroutine。当程序启动时,它会自动创建

生成 go.mod文件:

1
  Go mod init mod-demo

执行命令go list -m all 查看当前所有依赖项

Go web 框架 Gin (https://gin-gonic.com/) (https://github.com/gin-gonic/gin)

use the below Go command to install Gin.

1
go get -u github.com/gin-gonic/gin

Import it in your code:

1
import "github.com/gin-gonic/gin"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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, hello world!",
		})
	})
	r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
Licensed under CC BY-NC-SA 4.0