diff --git a/html/index.html b/html/index.html index ef9feb7..4c2e45d 100644 --- a/html/index.html +++ b/html/index.html @@ -23,5 +23,10 @@
+
+
+
+
+
diff --git a/html/js/thermostat.js b/html/js/thermostat.js index e8a758a..cd2f3e7 100644 --- a/html/js/thermostat.js +++ b/html/js/thermostat.js @@ -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) diff --git a/main.go b/main.go index 80d1188..02bf01d 100644 --- a/main.go +++ b/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"` diff --git a/web.go b/web.go index 40079a2..1b31b53 100644 --- a/web.go +++ b/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))