diff --git a/main.go b/main.go index 1572aa1..6d3187e 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ import ( "embed" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" - "html/template" "io/fs" m "k8s-manager/src" "net/http" @@ -18,17 +17,17 @@ func main() { r := gin.Default() - r.SetFuncMap(template.FuncMap{ - "inc": m.Inc, - }) - - tmp := template.Must(template.New(""). - Funcs(template.FuncMap{ - "inc": m.Inc, - }). - ParseFS(f, "template/*")) - - r.SetHTMLTemplate(tmp) + //r.SetFuncMap(template.FuncMap{ + // "inc": m.Inc, + //}) + // + //tmp := template.Must(template.New(""). + // Funcs(template.FuncMap{ + // "inc": m.Inc, + // }). + // ParseFS(f, "template/*")) + // + //r.SetHTMLTemplate(tmp) fp, _ := fs.Sub(f, "static") r.StaticFS("/static", http.FS(fp)) @@ -42,6 +41,7 @@ func main() { r.DELETE("/dep", m.JWTAuthMiddleware, m.CreateDeleteDeployment) r.GET("/login/:username", Test) + r.GET("/username", m.JWTAuthMiddleware, m.GetUsername) err := r.Run(":8000") if err != nil { log.Fatal(err) diff --git a/src/app_viewmodel.go b/src/app_viewmodel.go index 778e4a6..4e7fa58 100644 --- a/src/app_viewmodel.go +++ b/src/app_viewmodel.go @@ -4,7 +4,6 @@ import ( "encoding/json" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" - "github.com/thoas/go-funk" "net/http" "strings" ) @@ -49,18 +48,20 @@ func statusString(a *AppViewModel) string { } func AppPage(c *gin.Context) { - username := c.MustGet("username").(string) - appsvm := funk.Map(GetApps(username), func(a AppModel) AppViewModel { return AppViewModel{AppModel: &a} }).([]AppViewModel) - for i := range appsvm { - a := &appsvm[i] - a.Status = statusString(a) - a.ServiceDisplayName = a.ServiceName() - } - vm := &AppsViewModel{ - Username: username, - Apps: appsvm, - } - c.HTML(http.StatusOK, "app_view.html", vm) + //username := c.MustGet("username").(string) + //appsvm := funk.Map(GetApps(username), func(a AppModel) AppViewModel { return AppViewModel{AppModel: &a} }).([]AppViewModel) + //for i := range appsvm { + // a := &appsvm[i] + // a.Status = statusString(a) + // a.ServiceDisplayName = a.ServiceName() + //} + //vm := &AppsViewModel{ + // Username: username, + // Apps: appsvm, + //} + + c.File("template/app_view.html") + // c.HTML(http.StatusOK, "app_view.html", vm) } func AppMiddleware(c *gin.Context) { @@ -109,3 +110,8 @@ func GetAppsController(c *gin.Context) { apps := GetApps(username) c.JSON(http.StatusOK, apps) } + +func GetUsername(c *gin.Context) { + username := c.MustGet("username").(string) + c.JSON(http.StatusOK, gin.H{"username": username}) +} diff --git a/template/app_view.html b/template/app_view.html index 3ba4743..69149ef 100644 --- a/template/app_view.html +++ b/template/app_view.html @@ -4,21 +4,22 @@ +