about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <git@emile.space>2024-08-17 01:04:10 +0200
committerEmile <git@emile.space>2024-08-17 01:04:10 +0200
commitf2f14353432c70f11973cdf865a002a267c3bd92 (patch)
tree39ff7c0676a448b4db0a1c6f4ac9e70865e811eb
parent93219b7c02da4c07fbebc4cdd3651ec111c8daea (diff)
added a version read via env var
-rw-r--r--src/battle.go4
-rw-r--r--src/bot.go10
-rw-r--r--src/http.go2
-rw-r--r--src/user.go5
-rw-r--r--templates/nav.html2
5 files changed, 21 insertions, 2 deletions
diff --git a/src/battle.go b/src/battle.go
index 2723409..7aa949a 100644
--- a/src/battle.go
+++ b/src/battle.go
@@ -5,6 +5,7 @@ import (
 	"html/template"
 	"log"
 	"net/http"
+	"os"
 	"strconv"
 	"strings"
 	"time"
@@ -337,6 +338,7 @@ func battlesHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 		data["pagelink1"] = Link{Name: "battle", Target: "/battle"}
 		data["pagelink1options"] = []Link{
 			{Name: "bot", Target: "/bot"},
@@ -385,6 +387,7 @@ func battleNewHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 
 		// breadcrumb foo
 		session, _ := globalState.sessions.Get(r, "session")
@@ -540,6 +543,7 @@ func battleSingleHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 		data["pagelink1"] = Link{"battle", "/battle"}
 		data["pagelink1options"] = []Link{
 			{Name: "user", Target: "/user"},
diff --git a/src/bot.go b/src/bot.go
index 0a07b35..a2e8c99 100644
--- a/src/bot.go
+++ b/src/bot.go
@@ -5,6 +5,7 @@ import (
 	"html/template"
 	"log"
 	"net/http"
+	"os"
 	"strconv"
 	"strings"
 	"time"
@@ -357,6 +358,7 @@ func botsHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 
 		session, _ := globalState.sessions.Get(r, "session")
 		username := session.Values["username"]
@@ -414,6 +416,7 @@ func botSingleHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 		data["pagelink1"] = Link{"bot", "/bot"}
 		data["pagelink1options"] = []Link{
 			{Name: "user", Target: "/user"},
@@ -475,7 +478,11 @@ func botSingleHandler(w http.ResponseWriter, r *http.Request) {
 		allBotNames, err := BotGetAll()
 		var opts []Link
 		for _, bot := range allBotNames {
-			opts = append(opts, Link{Name: bot.Name, Target: fmt.Sprintf("/%d", bot.ID)})
+
+			// don't add the current bot to the list, we're already on that page!
+			if bot.ID != botid {
+				opts = append(opts, Link{Name: bot.Name, Target: fmt.Sprintf("/%d", bot.ID)})
+			}
 		}
 		data["pagelink2options"] = opts
 
@@ -666,6 +673,7 @@ func botNewHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 
 		session, _ := globalState.sessions.Get(r, "session")
 		username := session.Values["username"].(string)
diff --git a/src/http.go b/src/http.go
index 6cbbce8..9690db6 100644
--- a/src/http.go
+++ b/src/http.go
@@ -5,6 +5,7 @@ import (
 	"html/template"
 	"log"
 	"net/http"
+	"os"
 )
 
 type Link struct {
@@ -17,6 +18,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 		data["pagelink1"] = ""
 		data["pagelinknext"] = []Link{
 			{Name: "user/", Target: "/user"},
diff --git a/src/user.go b/src/user.go
index 2285394..48bc299 100644
--- a/src/user.go
+++ b/src/user.go
@@ -226,6 +226,7 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
 		// define data
 		log.Println("[d] Defining breadcrumbs")
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 		data["pagelink1"] = Link{"login", "/login"}
 		data["pagelink1options"] = []Link{
 			{Name: "register", Target: "/register"},
@@ -323,6 +324,7 @@ func registerHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 
 		// get the session
 		session, _ := globalState.sessions.Get(r, "session")
@@ -424,6 +426,7 @@ func userHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 		data["pagelink1"] = Link{"user", "/user"}
 		data["pagelink1options"] = []Link{
 			{Name: "bot", Target: "/bot"},
@@ -491,6 +494,7 @@ func usersHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 		data["pagelink1"] = Link{Name: "user", Target: "/user"}
 		data["pagelink1options"] = []Link{
 			{Name: "bot", Target: "/bot"},
@@ -545,6 +549,7 @@ func profileHandler(w http.ResponseWriter, r *http.Request) {
 	case "GET":
 		// define data
 		data := map[string]interface{}{}
+		data["version"] = os.Getenv("VERSION")
 		data["pagelink1"] = Link{"user", "/user"}
 		data["pagelink1options"] = []Link{
 			{Name: "bot", Target: "/bot"},
diff --git a/templates/nav.html b/templates/nav.html
index c00c880..ea1e1af 100644
--- a/templates/nav.html
+++ b/templates/nav.html
@@ -49,7 +49,7 @@
     </ul>
     <ul style="float: right">
         <li>
-            <a href="https://github.com/HanEmile/r2wars-web">src</a>
+            <a href="https://github.com/HanEmile/r2wars-web">{{ .version }} src</a>
         </li>
     </ul>
   </nav>