LoginSignup
2
2

More than 1 year has passed since last update.

【Go】GinでURLからパラメーターを受け取る2つの方法

Last updated at Posted at 2022-05-24

概要

Ginを使用したAPI開発などでURLからパラメーターを受け取る際、
パラメーターの種類によって受け取り方が異なるのでまとめました。

クエリパラメータ
http://example.com/user?id=123

パスパラメータ
http://example.com/user/123

受け取り方

クエリパラメータの場合
router.GET("/user", func(ctx *gin.Context) {
  id := ctx.Query("id")
})
パスパラメータの場合
router.GET("/user/:id", func(ctx *gin.Context) {
  ctx.Param("id")
})

以上です。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2