| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package router
- import (
- "demo/data/dao"
- "demo/share"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/spf13/cast"
- "net/http"
- )
- func TestRouth(engine *gin.RouterGroup) {
- user := engine.Group("/test")
- {
- PushRouter(user, "POST", "/order/pay", OrderSubmit)
- PushRouter(user, "POST", "/test", DataTest)
- PushRouter(user, "POST", "/home", Home)
- }
- }
- func OrderSubmit(c *gin.Context) {
- id := GetUserIdByToken(c)
- if id == 0 {
- return
- }
- data := share.GetJsonAnyParam(c)
- orderId, _ := data("orderId")
- err := dao.OrderPaySuccess(cast.ToInt64(orderId), id)
- if err != nil {
- c.JSON(200, CreateResultError(401, err.Error()))
- return
- }
- c.JSON(200, CreateResult())
- }
- func DataTest(c *gin.Context) {
- body := make(map[string]interface{})
- c.ShouldBindJSON(&body)
- fmt.Println("router:", body)
- fmt.Println("router:", c.Request.Body)
- c.JSON(200, CreateResultData("test"))
- }
- func Home(c *gin.Context) {
- data, err := dao.GetAdviceData()
- if err != nil {
- panic(err)
- }
- c.HTML(http.StatusOK, "index.html", data)
- }
|