go gin框架基本網路請求

2021-10-19 10:08:46 字數 2137 閱讀 3637

gin框架中 

1:引入mysql的請求

2:gin.default()獲取,網路請求,get,post,delete方式請求

3:以json map的形式返回

4:以json struct的形式返回

//不用handle 方法,直接用post函式

router.post("/login2", func(context *gin.context) else

})router.delete("/delete/:id", func(context *gin.context) )

router.post("/login3", func(context *gin.context)

fmt.println(register.password + "\n")

fmt.println(register.username)

context.writer.write(byte(register.username + "login") )

})router.post("/login4", func(context *gin.context)

fmt.println("s")

fmt.println(register.username + "\n")

fmt.println(register.password)

context.writer.write(byte("login4" + register.username))

})router.get("/hellostring", func(context *gin.context) )

//以json map的形式返回

router.get("/hellojson", func(context *gin.context) )

})router.get("/hellostruct", func(context *gin.context)

context.json(200,&jsonstruct)

})// 預設埠是8080,也可以指定埠 r.run(":80")

router.run()

}type register struct

type jsonstruct struct `json:"data"`

}type person struct

go gin框架使用cas單點登入

最近在用gin框架,想路由乙個路徑到cas單點登入發現有個小坑,小小的記錄一下。func 某方法 官方的 如果不用gin框架的話沒有問題,因為是單獨監聽8080埠,然後捕捉到請求就執行handlefunc方法,這裡cas是使用了 gopkg.in cas.v2 這個包,封裝了自己的handle和se...

retrofit網路請求框架

android studio可引用gradle compile 整合retrofit compile com.squareup.retrofit2 retrofit 2.1.0 首先建立乙個inte ce請求介面 註解對應的包如下 import retrofit2.http.path 以下請求介面 ...

Go gin框架中增加pprof分析效能

gofly客服websocket部分存在groutine洩露 在每次連線ws的時候都開啟了groutine 但是沒有關閉 pprof是go標準庫自帶的功能 引進去就能分析程式中的效能問題 在gin框架下可以使用第三方的 github.com gin contrib pprof engine gin....