8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Golang】Ginでサブルーティングの定義方法

Posted at

やりたいこと

ルーティングを作る時にグルーピングを多段化させたい時ってあると思います。
その方法について記載します。

方法

router := gin.Default()

// api
v1 := router.Group("api/v1")
{
  // 以下のようにv1.Groupとしてv1を引き継いでGroupを作成する
  hoges := v1.Group("/hoges")
  {
    hoges.GET("/", func(c *gin.Context) {
      c.JSON(200, gin.H{
        "message": "hello",
      })
    })
  }
}
8
5
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
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?