Make Application name configurable

This commit is contained in:
Thomas Peetz
2019-09-03 15:42:48 +02:00
parent b7cbe08d7b
commit 276e65b153
15 changed files with 359 additions and 12 deletions
+9 -3
View File
@@ -2,8 +2,10 @@ package util
import (
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/auth"
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/properties"
"net/http"
"fmt"
"github.com/gin-gonic/gin"
)
@@ -19,7 +21,11 @@ const (
// Render one of HTML, JSON or CSV based on the 'Accept' header of the request
// If the header doesn't specify this, HTML is rendered, provided that
// the template name is present
func Render(c *gin.Context, data gin.H, templateName string) {
func Render(c *gin.Context, data gin.H, templateName string, prefix bool) {
var fullTemplateName = templateName
if prefix {
fullTemplateName = fmt.Sprintf("%s/%s", properties.TemplatePrefix, templateName)
}
auth.SetSessionData(c, data)
switch c.Request.Header.Get("Accept") {
case "application/json":
@@ -27,7 +33,7 @@ func Render(c *gin.Context, data gin.H, templateName string) {
case "application/xml":
c.XML(http.StatusOK, data["payload"])
default:
c.HTML(http.StatusOK, templateName, data)
c.HTML(http.StatusOK, fullTemplateName, data)
}
}
@@ -35,5 +41,5 @@ func Render(c *gin.Context, data gin.H, templateName string) {
func ShowIndexPage(c *gin.Context) {
// Call the render function with the name of the template to render
//log.Printf("Context: %v", c)
Render(c, gin.H{"title": "Kalorienmanager", "payload": nil}, "index.html")
Render(c, gin.H{"title": properties.Application, "payload": nil}, "index.html", true)
}