Home > Backend Development > Golang > Is golang not suitable for web development?

Is golang not suitable for web development?

(*-*)浩
Release: 2019-12-14 13:32:36
Original
9788 people have browsed it

Is golang not suitable for web development?

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
Copy after login

Among them worth it One thing to mention is that beggo is a project developed and maintained by Chinese people. As the initial learning stage, we chose the famous gin project to explore.

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
Copy after login

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
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template