MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / runGoHTTPServer

Function runGoHTTPServer

pkg/httpcli/httpcli_test.go:22–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22func runGoHTTPServer() string {
23 serverAddr, requestAddr := utils.GetLocalHTTPAddrPairs()
24
25 gin.SetMode(gin.ReleaseMode)
26 r := gin.Default()
27 oKFun := func(c *gin.Context) {
28 uid := c.Query("uid")
29 fmt.Printf("request parameters: uid=%s\n", uid)
30 c.JSON(200, StdResult{
31 Code: 0,
32 Msg: "ok",
33 Data: fmt.Sprintf("uid=%v", uid),
34 })
35 }
36 errFun := func(c *gin.Context) {
37 uid := c.Query("uid")
38 fmt.Printf("request parameters: uid=%s\n", uid)
39 c.JSON(401, StdResult{
40 Code: 401,
41 Msg: "authorization failure",
42 Data: fmt.Sprintf("uid=%v", uid),
43 })
44 }
45
46 oKPFun := func(c *gin.Context) {
47 var body myBody
48 c.BindJSON(&body)
49 fmt.Println("body data:", body)
50 c.JSON(200, StdResult{
51 Code: 0,
52 Msg: "ok",
53 Data: body,
54 })
55 }
56 errPFun := func(c *gin.Context) {
57 var body myBody
58 c.BindJSON(&body)
59 fmt.Println("body data:", body)
60 c.JSON(401, StdResult{
61 Code: 401,
62 Msg: "authorization failure",
63 Data: nil,
64 })
65 }
66
67 r.GET("/get", oKFun)
68 r.GET("/get_err", errFun)
69 r.DELETE("/delete", oKFun)
70 r.DELETE("/delete_err", errFun)
71 r.POST("/post", oKPFun)
72 r.POST("/post_err", errPFun)
73 r.PUT("/put", oKPFun)
74 r.PUT("/put_err", errPFun)
75 r.PATCH("/patch", oKPFun)
76 r.PATCH("/patch_err", errPFun)
77
78 go func() {
79 err := r.Run(serverAddr)

Callers 10

TestGetStandardFunction · 0.85
TestDeleteStandardFunction · 0.85
TestPostStandardFunction · 0.85
TestPutStandardFunction · 0.85
TestPatchStandardFunction · 0.85
TestGetFunction · 0.85
TestDeleteFunction · 0.85
TestPostFunction · 0.85
TestPutFunction · 0.85
TestPatchFunction · 0.85

Calls 10

GetLocalHTTPAddrPairsFunction · 0.92
PrintfMethod · 0.80
BindJSONMethod · 0.80
PrintlnMethod · 0.80
GETMethod · 0.80
DELETEMethod · 0.80
POSTMethod · 0.80
PUTMethod · 0.80
PATCHMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected