HomeNav/cmd/APP/main.go

44 lines
918 B
Go
Raw Permalink Normal View History

2023-12-13 14:51:04 +08:00
package main
import (
2023-12-15 00:47:09 +08:00
"HomeNav/middleware"
2023-12-13 17:42:38 +08:00
"fmt"
2023-12-13 14:51:04 +08:00
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
router := gin.Default()
// 设置 webhook 路由
router.POST("/webhook", func(c *gin.Context) {
var json map[string]interface{}
// 将请求的 JSON 绑定到 json 变量
if err := c.BindJSON(&json); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
// 处理 webhook 数据
// 在这里,我们只是简单地打印出接收到的数据
2023-12-13 17:42:38 +08:00
//println("Received webhook:", len(json))
2023-12-13 14:51:04 +08:00
2023-12-13 17:42:38 +08:00
fmt.Printf("q: %v\n", json)
c.String(http.StatusBadRequest, "success")
})
router.GET("/q", func(c *gin.Context) {
2023-12-15 00:47:09 +08:00
//c.JSON(http.StatusOK, gin.H{
// "sss": "sss",
//})
middleware.Hello()
// 输出html H1标签
c.String(http.StatusOK, "<h1>hello world</h1>")
2023-12-13 14:51:04 +08:00
})
// 启动服务器
router.Run(":8888") // 监听并在 0.0.0.0:8080 上启动服务
}