In terms of network programming, Go language is widely used in Web applications, API applications, download applications, etc.; ##It is very convenient to use go language for web development. If you don't use a framework, you can quickly develop a web application by just using the net/http package.
However, the official package does not support RESTful style API, so we still need to choose a framework to help us develop. We enter web on github, select the go language project, and sort by the number of stars. There are probably the following projects, which are relatively popular in the community:
caddy gin beego martini gotty echo revel iris
Create project installation dependencies
mkdir gin-demo // add to env var cd gin-demo go get github.com/gin-gonic/gin cd src touch main.go
Hello World
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 }
When we run this code, the program It will listen to port 8080 and access it through the browser, and pong will be displayed on the page. Analyze this code. First, import the gin package, obtain an engine instance, and then distribute routes and monitor ports.
The above is the detailed content of Is golang not suitable for web development?. For more information, please follow other related articles on the PHP Chinese website!