diff --git a/api/http/gin.go b/api/http/gin.go index 411b508..7dab07c 100644 --- a/api/http/gin.go +++ b/api/http/gin.go @@ -2,7 +2,6 @@ package http import ( "fmt" - "net/http" "github.com/gin-gonic/gin" @@ -18,9 +17,7 @@ type GinAdapter struct { } func (g *GinAdapter) IndexHandler(c *gin.Context) { - c.HTML(http.StatusOK, "page_index", gin.H{ - "title": "TH7", - }) + c.File("./static/index.html") } func NewGinAdapter(corePort ports.CorePort, cfg config.Config) *GinAdapter { @@ -35,23 +32,23 @@ func NewGinAdapter(corePort ports.CorePort, cfg config.Config) *GinAdapter { adapter.router = gin.New() // API - adapter.router.GET("/data/channel/:id", adapter.GetChannelByIDHandler) - adapter.router.GET("/data/channels", adapter.GetChannelsHandler) - adapter.router.GET("/data/ratio", adapter.GetRatioHandler) - adapter.router.GET("/data", adapter.GetDataHandler) + 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) - adapter.router.GET("/config/channel/:id", adapter.GetConfigChannelByIdHandler) - adapter.router.GET("/config/channels", adapter.GetConfigChannelsHandler) - adapter.router.GET("/config/device", adapter.GetConfigDeviceHandler) - adapter.router.GET("/config/db", adapter.GetConfigDBHandler) + 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) - adapter.router.POST("/config/device", adapter.SetConfigDeviceHandler) - adapter.router.POST("/config/channel/:id", adapter.SetConfigChannelByIdHandler) - adapter.router.POST("/config/db", adapter.SetConfigDBHandler) + 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) - adapter.router.LoadHTMLGlob("./templates/*.tmpl") - adapter.router.Static("/assets", "./static") + // TH7 demo code. html file and javascript adapter.router.GET("/", adapter.IndexHandler) + adapter.router.Static("/assets", "./static") return &adapter } diff --git a/static/data-updater.js b/static/data-updater.js index 7650d8e..8eb6f22 100644 --- a/static/data-updater.js +++ b/static/data-updater.js @@ -74,18 +74,18 @@ function updateOthers(data) { } async function updateRead() { - const data = await fetchData("/data"); + const data = await fetchData("/v1/data"); updateTable(data, "read", readOldChannelCount, updateReadTable); updateOthers(data); } async function updateConfig() { - const data = await fetchData("/config"); - updateTable(data.config, "config", configOldChannelCount, updateConfigTable); + const data = await fetchData("/v1/config/channels"); + updateTable(data, "config", configOldChannelCount, updateConfigTable); } updateRead(); updateConfig(); setInterval(updateRead, 1000); -setInterval(updateConfig, 5000); +setInterval(updateConfig, 10000); diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..502a070 --- /dev/null +++ b/static/index.html @@ -0,0 +1,94 @@ + + + + + + + TH7 demo + + + +

TH7

+ + + + + + + + +
ChannelValue
+ +

VDD:

+

VREF:

+

VADJ:

+

Last updated:

+ +

Thermocouple config

+ + + + + + + + + + + + +
ChannelTypeGainOffsetFilter sizeFilter type
+ + + + diff --git a/templates/index.tmpl b/templates/index.tmpl deleted file mode 100644 index b406300..0000000 --- a/templates/index.tmpl +++ /dev/null @@ -1,92 +0,0 @@ -{{ define "page_index" }} - - - - - - - {{.title}} - - - -

TH7

- - - - - - - - -
ChannelValue
- -

VDD:

-

VREF:

-

VADJ:

-

Last updated:

- -

Thermocouple config

- - - - - - - - - - - - -
ChannelTypeGainOffsetFilter sizeFilter type
- - - - -{{ end }}