Import sources from Kontor

This commit is contained in:
Thomas Peetz
2019-06-18 18:33:38 +02:00
parent fa3286c8e2
commit f326e994da
20 changed files with 1262 additions and 3 deletions
+39
View File
@@ -0,0 +1,39 @@
package util
import (
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/auth"
"net/http"
"github.com/gin-gonic/gin"
)
const (
// SaveAction defines label of button.
SaveAction = "Save"
// AddAction defines label of button.
AddAction = "Add"
// DeleteAction defines label of button.
DeleteAction = "Delete"
)
// 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) {
auth.SetSessionData(c, data)
switch c.Request.Header.Get("Accept") {
case "application/json":
c.JSON(http.StatusOK, data["payload"])
case "application/xml":
c.XML(http.StatusOK, data["payload"])
default:
c.HTML(http.StatusOK, templateName, data)
}
}
// ShowIndexPage render the index page of Kontor web application.
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")
}