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, World!", }) }) r.Run() }
package main import "github.com/gin-gonic/gin" func main() { r := gin.Default() r.GET("/hello", func(c *gin.Context) { name := c.Query("name") c.JSON(200, gin.H{ "message": "Hello, " + name + "!", }) }) r.Run() }In this example, we create a new gin-gonic/gin engine and use its `GET` method to create a handler function for the `/hello` route. The function reads a `name` query parameter from the request and sends a JSON response with a "message" property set to "Hello, {name}!". For example, a request to `/hello?name=John` would result in a response with "Hello, John!". Overall, the gin-gonic/gin package/library provides a powerful and flexible framework for building web applications in Go, with robust support for handling HTTP requests using the GET method. Whether you're building a simple API or a complex web application, gin-gonic/gin is a great starting point for your next Go project.