From 1f51ef966803a6d262bd217412b598870f15b479 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Tue, 30 Jun 2020 17:48:26 -0700 Subject: [PATCH] Add version string to config endpoint --- config/config.go | 6 +++++- controllers/config.go | 6 +++--- main.go | 2 +- webroot/js/app.js | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index fa16cd8cb..ea3e2bcf2 100644 --- a/config/config.go +++ b/config/config.go @@ -24,6 +24,7 @@ type config struct { WebServerPort int `yaml:"webServerPort"` S3 s3 `yaml:"s3"` InstanceDetails InstanceDetails `yaml:"instanceDetails"` + VersionInfo string `yaml:"-"` } // InstanceDetails defines the user-visible information about this particular instance. @@ -35,6 +36,7 @@ type InstanceDetails struct { Tags []string `yaml:"tags" json:"tags"` SocialHandles []socialHandle `yaml:"socialHandles" json:"socialHandles"` ExtraInfoFile string `yaml:"extraUserInfoFileName" json:"extraUserInfoFileName"` + Version string `json:"version"` } type socialHandle struct { @@ -142,12 +144,14 @@ func (c *config) verifySettings() error { } //Load tries to load the configuration file -func Load(filePath string) error { +func Load(filePath string, versionInfo string) error { Config = new(config) if err := Config.load(filePath); err != nil { return err } + Config.VersionInfo = versionInfo + return Config.verifySettings() } diff --git a/controllers/config.go b/controllers/config.go index 502029a81..19685a2b2 100644 --- a/controllers/config.go +++ b/controllers/config.go @@ -12,7 +12,7 @@ import ( func GetWebConfig(w http.ResponseWriter, r *http.Request) { middleware.EnableCors(&w) - config := config.Config.InstanceDetails - - json.NewEncoder(w).Encode(config) + configuration := config.Config.InstanceDetails + configuration.Version = config.Config.VersionInfo + json.NewEncoder(w).Encode(configuration) } diff --git a/main.go b/main.go index 72015a382..473625acb 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ func main() { logrus.SetReportCaller(true) } - if err := config.Load(*configFile); err != nil { + if err := config.Load(*configFile, getVersion()); err != nil { panic(err) } diff --git a/webroot/js/app.js b/webroot/js/app.js index 331267697..e7455a6c8 100644 --- a/webroot/js/app.js +++ b/webroot/js/app.js @@ -47,7 +47,7 @@ async function setupApp() { app.summary = config.summary && addNewlines(config.summary); app.tags = config.tags; app.title = config.title; - app.appVersion = config.appVersion; + app.appVersion = config.version; try {