use router group

This commit is contained in:
William Clark 2023-12-13 08:21:30 +00:00
parent dcd1a03c69
commit eda649c65f

View File

@ -28,7 +28,7 @@ func NewGinAdapter(corePort ports.CorePort, cfg config.Config) *GinAdapter {
adapter.port = cfg.API.Port
adapter.cfg = cfg
//gin.SetMode(gin.ReleaseMode)
gin.SetMode(gin.ReleaseMode)
adapter.router = gin.New()
@ -37,15 +37,20 @@ func NewGinAdapter(corePort ports.CorePort, cfg config.Config) *GinAdapter {
go manager.start()
// API
adapter.router.GET("/v1/data/channel/:id", adapter.GetChannelByIDHandler)
adapter.router.GET("/v1/data/channels", adapter.GetChannelsHandler)
adapter.router.GET("/v1/data/ratio", adapter.GetRatioHandler)
adapter.router.GET("/v1/data", adapter.GetDataHandler)
v1 := adapter.router.Group("/v1")
v1.GET("/data/channel/:id", adapter.GetChannelByIDHandler)
v1.GET("/data/channels", adapter.GetChannelsHandler)
v1.GET("/data/ratio", adapter.GetRatioHandler)
v1.GET("/data", adapter.GetDataHandler)
adapter.router.GET("/v1/config/channel/:id", adapter.GetConfigChannelByIdHandler)
adapter.router.GET("/v1/config/channels", adapter.GetConfigChannelsHandler)
adapter.router.GET("/v1/config/device", adapter.GetConfigDeviceHandler)
adapter.router.GET("/v1/config/db", adapter.GetConfigDBHandler)
v1.GET("/config/channel/:id", adapter.GetConfigChannelByIdHandler)
v1.GET("/config/channels", adapter.GetConfigChannelsHandler)
v1.GET("/config/device", adapter.GetConfigDeviceHandler)
v1.GET("/config/db", adapter.GetConfigDBHandler)
v1.POST("/config/device", adapter.SetConfigDeviceHandler)
v1.POST("/config/channel/:id", adapter.SetConfigChannelByIdHandler)
v1.POST("/config/db", adapter.SetConfigDBHandler)
adapter.router.GET("/ws", func(c *gin.Context) {
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
@ -67,10 +72,6 @@ func NewGinAdapter(corePort ports.CorePort, cfg config.Config) *GinAdapter {
// start web socket service that dumps new data to websocket chan
go startService(manager, corePort)
adapter.router.POST("/v1/config/device", adapter.SetConfigDeviceHandler)
adapter.router.POST("/v1/config/channel/:id", adapter.SetConfigChannelByIdHandler)
adapter.router.POST("/v1/config/db", adapter.SetConfigDBHandler)
// TH7 demo code. html file and javascript
adapter.router.GET("/", adapter.IndexHandler)
adapter.router.Static("/assets", "./static")