feat(Go-StudyExample): 2020/12/9 :新增Gin框架使用示例
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* @Author : huangzj
|
||||
* @Time : 2020/12/8 9:31
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
package gin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJsonp(t *testing.T) {
|
||||
r := gin.Default()
|
||||
|
||||
r.GET("/JSONP?callback=x", func(c *gin.Context) {
|
||||
data := map[string]interface{}{
|
||||
"foo": "bar",
|
||||
}
|
||||
|
||||
// callback 是 x
|
||||
// 将输出:x({\"foo\":\"bar\"})
|
||||
c.JSONP(http.StatusOK, data)
|
||||
})
|
||||
|
||||
// 监听并在 0.0.0.0:8080 上启动服务
|
||||
err := r.Run(":8080")
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user