package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
type Message struct {
Text string `json:"text"`
}
func main() {
// 1.创建路由
r := gin.Default()
// 2.绑定路由规则,执行的函数
// gin.Context,封装了request和response
r.GET("/", func(c *gin.Context) {
msg := Message{Text: "Hello World!"}
c.JSON(http.StatusOK, msg)
})
// 3.监听端口,默认在8080
// Run("里面不指定端口号默认为8080")
r.Run(":8000")
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交