GoLearning/Example/1.Gin_Helloworld/main.go

29 lines
472 B
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
// 创建Gin引擎
r := gin.Default()
// 配置静态文件路径
//r.Static("/static", "./static")
r.LoadHTMLGlob("static/*")
// 定义GET请求处理程序返回HTML响应
r.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", gin.H{})
// c.JSON(http.StatusOK, gin.H{
// "message": "Hello, World!",
// })
})
// 启动HTTP服务器
r.Run(":8080")
}