func main() { router := gin.Default() router.GET("/hello", func(c *gin.Context) { name := c.Query("name") c.JSON(http.StatusOK, gin.H{"message": "Hello " + name}) }) router.Run(":8080") }
func main() { router := gin.Default() router.LoadHTMLGlob("templates/*") router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index.tmpl", gin.H{ "title": "Home", }) }) router.Run(":8080") }In the above example, we create a gin router and use the "LoadHTMLGlob()" function to load all the HTML templates contained in the "templates/" directory. We define a GET route for "/", which renders the "index.tmpl" template and passes a "title" variable to the template. The rendered HTML is returned as a response.