use router group
This commit is contained in:
parent
dcd1a03c69
commit
eda649c65f
27
api/api.go
27
api/api.go
@ -28,7 +28,7 @@ func NewGinAdapter(corePort ports.CorePort, cfg config.Config) *GinAdapter {
|
|||||||
adapter.port = cfg.API.Port
|
adapter.port = cfg.API.Port
|
||||||
adapter.cfg = cfg
|
adapter.cfg = cfg
|
||||||
|
|
||||||
//gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
|
||||||
adapter.router = gin.New()
|
adapter.router = gin.New()
|
||||||
|
|
||||||
@ -37,15 +37,20 @@ func NewGinAdapter(corePort ports.CorePort, cfg config.Config) *GinAdapter {
|
|||||||
go manager.start()
|
go manager.start()
|
||||||
|
|
||||||
// API
|
// API
|
||||||
adapter.router.GET("/v1/data/channel/:id", adapter.GetChannelByIDHandler)
|
v1 := adapter.router.Group("/v1")
|
||||||
adapter.router.GET("/v1/data/channels", adapter.GetChannelsHandler)
|
v1.GET("/data/channel/:id", adapter.GetChannelByIDHandler)
|
||||||
adapter.router.GET("/v1/data/ratio", adapter.GetRatioHandler)
|
v1.GET("/data/channels", adapter.GetChannelsHandler)
|
||||||
adapter.router.GET("/v1/data", adapter.GetDataHandler)
|
v1.GET("/data/ratio", adapter.GetRatioHandler)
|
||||||
|
v1.GET("/data", adapter.GetDataHandler)
|
||||||
|
|
||||||
adapter.router.GET("/v1/config/channel/:id", adapter.GetConfigChannelByIdHandler)
|
v1.GET("/config/channel/:id", adapter.GetConfigChannelByIdHandler)
|
||||||
adapter.router.GET("/v1/config/channels", adapter.GetConfigChannelsHandler)
|
v1.GET("/config/channels", adapter.GetConfigChannelsHandler)
|
||||||
adapter.router.GET("/v1/config/device", adapter.GetConfigDeviceHandler)
|
v1.GET("/config/device", adapter.GetConfigDeviceHandler)
|
||||||
adapter.router.GET("/v1/config/db", adapter.GetConfigDBHandler)
|
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) {
|
adapter.router.GET("/ws", func(c *gin.Context) {
|
||||||
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
|
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
|
// start web socket service that dumps new data to websocket chan
|
||||||
go startService(manager, corePort)
|
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
|
// TH7 demo code. html file and javascript
|
||||||
adapter.router.GET("/", adapter.IndexHandler)
|
adapter.router.GET("/", adapter.IndexHandler)
|
||||||
adapter.router.Static("/assets", "./static")
|
adapter.router.Static("/assets", "./static")
|
||||||
|
Loading…
Reference in New Issue
Block a user