i dont know why /someJSON and /JSONP 404
this is engine trees have three routes ,and every router have three handle
but when request value handle is nil
value := root.getValue(rPath, c.params, c.skippedNodes, unescape)
this is router
package routers
import (
"gin-learn/app/api"
"github.com/gin-gonic/gin"
)
func SetUpRouter() *gin.Engine {
r := gin.Default()
//r.GET("/test ", api.Test2)
r.GET("/test1", api.TestGet)
r.GET("/someJSON ", api.SomeJSON)
r.GET("/JSONP ", api.JSONP)
return r
}
this is api
package api
import (
"github.com/gin-gonic/gin"
"net/http"
)
//使用 AsciiJSON 生成具有转义的非 ASCII 字符的 ASCII-only JSON。
func SomeJSON(c *gin.Context) {
data := map[string]interface{}{
"lang": "GO语言",
"tag": "<br>",
}
// 输出 : {"lang":"GO\u8bed\u8a00","tag":"\u003cbr\u003e"}
c.AsciiJSON(http.StatusOK, data)
}
func JSONP(c *gin.Context) {
data := map[string]interface{}{
"foo": "bar",
}
// /JSONP?callback=x
// 将输出:x({\"foo\":\"bar\"})
c.JSONP(http.StatusOK, data)
}
//get 请求获取参数
func TestGet(c *gin.Context) {
c.String(http.StatusOK, "1111")
}
Comment From: MichaelDeSteven
the path ending should not have blank space right "/SomeJSON"、“/JSONP” wrong "/SomeJSON "、“/JSONP ”
Comment From: ChenZheOnePiece
非常感谢,我找了好久没找到问题在哪