[Golang]API版本控制

package main

import (
	"fmt"

	"github.com/gin-gonic/gin"
	"example/webapp/api/v1"
)

r := gin.Default()

func main() {
    r := gin.Default()
    v1.GroupRouter(r)

	r.Run()

}

package v1

import (
	"fmt"
	"github.com/gin-gonic/gin"
	
)

func ApiTemp(router *gin.RouterGroup) {
	router.GET("/ping", func(c *gin.Context) {
		// queryparamerの値を取得する
		// fmt.Println(c.Query("samplequery"))
		c.JSON(200, gin.H{
			"Message": "v1 ping healthcheck",
		})
	})
}



func GroupRouter(check *gin.Engine){
	check.GET("/healthcheckcheck", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "healthcheckcheck",
		})
	})
	v1_path := check.Group("/v1")
	ApiTemp(v1_path)

}

广告
将在 10 秒后关闭
bannerAds