mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 16:49:42 +00:00
Display current version
This commit is contained in:
parent
6a623c3051
commit
ee4ca5347e
4 changed files with 30 additions and 5 deletions
|
|
@ -23,5 +23,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="container" id="thermostats"></div>
|
||||
<div class="container">
|
||||
<div class="row" style="margin-top: 10rem">
|
||||
<h6 id="version"></h6>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -64,5 +64,15 @@ function renderThermostats() {
|
|||
});
|
||||
};
|
||||
|
||||
function renderVersion() {
|
||||
$.ajax({
|
||||
url: jsconfig.baseurl + "/api/version"
|
||||
}).then(function(data) {
|
||||
var versionText = "TempGopher © 2018 Mike Shoup | Version: " + data.version;
|
||||
$("#version").text(versionText);
|
||||
});
|
||||
};
|
||||
$(document).ready(renderVersion);
|
||||
|
||||
$(document).ready(renderThermostats);
|
||||
setInterval(renderThermostats, 60000)
|
||||
|
|
|
|||
3
main.go
3
main.go
|
|
@ -7,6 +7,9 @@ import (
|
|||
"github.com/stianeikeland/go-rpio"
|
||||
)
|
||||
|
||||
// Version is the current code version of tempgopher
|
||||
const Version = "0.1.0-dev"
|
||||
|
||||
func main() {
|
||||
var args struct {
|
||||
Action string `arg:"required,positional" help:"run"`
|
||||
|
|
|
|||
17
web.go
17
web.go
|
|
@ -11,13 +11,9 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
"github.com/gobuffalo/packr"
|
||||
|
||||
>>>>>>> html
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gobuffalo/packr"
|
||||
)
|
||||
|
||||
// PingHandler responds to get requests with the message "pong".
|
||||
|
|
@ -77,6 +73,14 @@ func JSConfigHandler(config *Config) gin.HandlerFunc {
|
|||
return gin.HandlerFunc(fn)
|
||||
}
|
||||
|
||||
// VersionHandler responds to GET requests with the current version of tempgopher
|
||||
func VersionHandler(c *gin.Context) {
|
||||
type version struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
c.JSON(http.StatusOK, version{Version: Version})
|
||||
}
|
||||
|
||||
// SetupRouter initializes the gin router.
|
||||
func SetupRouter(config *Config, states *map[string]State) *gin.Engine {
|
||||
// If not specified, put gin in release mode
|
||||
|
|
@ -102,6 +106,9 @@ func SetupRouter(config *Config, states *map[string]State) *gin.Engine {
|
|||
r.GET("/api/status", StatusHandler(states))
|
||||
r.GET("/api/status/*alias", StatusHandler(states))
|
||||
|
||||
// API Version
|
||||
r.GET("/api/version", VersionHandler)
|
||||
|
||||
// Config
|
||||
r.GET("/api/config", ConfigHandler(config))
|
||||
r.GET("/api/config/*alias", ConfigHandler(config))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue