Home Backend Development Golang What does gin mean?

What does gin mean?

May 18, 2019 pm 02:29 PM
gin

What does gin mean?

Gin is a web framework written in Go and has the advantage of high performance.

1. Installation

Use go to download the gin library, command line input: go get github.com/gin-gonic/gin, generally use the required dependencies:

import "github.com/gin-gonic/gin"
import "net/http"
Copy after login

Two: Basic application

1.Query method in gin.Context: get URL parameter

package main
 
import (
    "github.com/gin-gonic/gin"
    "net/http"
)
 
func getQuery(context *gin.Context){
 
    userid := context.Query("userid")
    username := context.Query("username")
 
    context.String(http.StatusOK,userid+" "+username)
}
func main(){
    // 注册一个默认路由器
    router := gin.Default()
 
    //注册GET处理
    router.GET("/user", getQuery)
 
    //默认8080端口
    router.Run(":8088")
}
Copy after login

Browser output:

5 xiaoming
Copy after login
Copy after login

2.gin. Param method in Context: RESRful style URL parameter passing

package main
 
import (
    "github.com/gin-gonic/gin"
    "net/http"
)
 
func getParam(context *gin.Context){
 
    userid := context.Param("userid")
    username := context.Param("username")
 
    context.String(http.StatusOK,userid+" "+username)
}
func main(){
    // 注册一个默认路由器
    router := gin.Default()
 
    //注册GET处理
    //router.GET("/user", getQuery)
    router.GET("/user/:userid/:username",getParam)
    //默认8080端口
    router.Run(":8088")
}
Copy after login

Supplement: /:varname must match the corresponding one, /*varname must match all the following ones, and you cannot use more than one at the same time, otherwise a compilation error will be reported

Page output:

5 xiaoming
Copy after login
Copy after login

The above is the detailed content of What does gin mean?. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1653
14
PHP Tutorial
1251
29
C# Tutorial
1224
24
How to combine Go with Gin to export Mysql data to Excel table How to combine Go with Gin to export Mysql data to Excel table May 26, 2023 pm 09:15 PM

1. To achieve the goal, Golang uses excelize to export the table to the browser for downloading or saving it locally. The subsequent import will also be written here 2. The library used gogetgithub.com/xuri/excelize/v23, the project directory go-excel├─app│├─excelize││└─excelize.go│├─model││└─ sysUser.go│└─service│└─userService.go├─common│└─mysql.go├─go.mod├─go.sum├─main.go└─setting.json4. Main code writing

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

In today's era of rapid technological development, programming languages ​​are springing up like mushrooms after a rain. One of the languages ​​that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

How to handle static resource files in the Gin framework How to handle static resource files in the Gin framework Jun 23, 2023 am 10:54 AM

The Gin framework is a lightweight, fast, and flexible web framework that allows developers to build high-performance web applications through a simple and beautiful API. In web applications, static resource files (such as images, CSS, JavaScript, fonts, etc.) are usually unchanged, so these resource files need to be processed efficiently to improve application performance. In the Gin framework, processing static resource files is very simple. This article will introduce how to handle static resource files in the Gin framework. 1. In G

What are the most popular golang frameworks on the market? What are the most popular golang frameworks on the market? Jun 01, 2024 pm 08:05 PM

The most popular Go frameworks at present are: Gin: lightweight, high-performance web framework, simple and easy to use. Echo: A fast, highly customizable web framework that provides high-performance routing and middleware. GorillaMux: A fast and flexible multiplexer that provides advanced routing configuration options. Fiber: A performance-optimized, high-performance web framework that handles high concurrent requests. Martini: A modular web framework with object-oriented design that provides a rich feature set.

Detailed explanation of API documentation and automated testing in the Gin framework Detailed explanation of API documentation and automated testing in the Gin framework Jun 22, 2023 pm 09:43 PM

Gin is a web framework written in Golang. It has the advantages of efficiency, lightweight, flexibility, relatively high performance, and easy to use. In Gin framework development, API documentation and automated testing are very important. This article will take an in-depth look at API documentation and automated testing in the Gin framework. 1. API documentation API documentation is used to record the detailed information of all API interfaces to facilitate the use and understanding of other developers. The Gin framework provides a variety of API documentation tools, including Swagger, GoSwa

Explore the Go language framework: 5 choices not to be missed! Explore the Go language framework: 5 choices not to be missed! Feb 19, 2024 pm 02:29 PM

As a fast and efficient programming language, Go language has always been favored by programmers. In the Go language ecosystem, frameworks play a vital role in helping developers build applications faster. This article will introduce five Go language frameworks to let you understand their characteristics and usage. 1. Gin framework The Gin framework is a lightweight Web framework with fast and high performance characteristics. Use the Gin framework to quickly build RESTful APIs and web applications. Here is a simple example code:

Gin request process source code analysis Gin request process source code analysis Aug 04, 2023 pm 05:26 PM

The official req and resp will be saved in Context. And gin itself has added an extension to the official http.ResponseWriter function, that is, it has defined an interface gin.ResponseWriter.

See all articles