From b86be4c749888383be03219ecde66c92c2ecf943 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 18 Nov 2025 19:36:05 +0000 Subject: [PATCH] add a bunch of comments to important code --- app/app.go | 4 ++++ app/common/types.go | 18 ++++++++++++++++-- app/common/utils.go | 13 +++---------- app/routes/account.go | 3 +++ app/routes/index.go | 34 +++++++++++++++++++++------------- app/routes/login.go | 1 - 6 files changed, 47 insertions(+), 26 deletions(-) diff --git a/app/app.go b/app/app.go index 312bce9..81d97b7 100644 --- a/app/app.go +++ b/app/app.go @@ -14,6 +14,7 @@ import ( func Run(configPath *string) { common.Global = common.GetConfig(*configPath) + // setup static resources gin.SetMode(gin.ReleaseMode) router := gin.Default() m := common.InitMinify() @@ -21,6 +22,7 @@ func Run(configPath *string) { html := common.MinifyStatic(m, web.Templates) common.TMPL = common.LoadHTMLToGin(router, html) + // dynamic routes for pages and page fragments router.GET("/", routes.HandleGETIndex) router.GET("/index", routes.HandleGETIndex) router.GET("/index/instances", routes.HandleGETInstancesFragment) @@ -35,9 +37,11 @@ func Run(configPath *string) { router.GET("/login", routes.HandleGETLogin) router.GET("/settings", routes.HandleGETSettings) + // run on all interfaces with port log.Fatal(router.Run(fmt.Sprintf("0.0.0.0:%d", common.Global.Port))) } +// setup static resources under web (css, images, modules, scripts) func ServeStatic(router *gin.Engine, m *minify.M) { css := common.MinifyStatic(m, web.CSS_fs) router.GET("/css/*css", func(c *gin.Context) { diff --git a/app/common/types.go b/app/common/types.go index aeaa9c6..f38ad5c 100644 --- a/app/common/types.go +++ b/app/common/types.go @@ -1,5 +1,9 @@ package common +import "html/template" + +var Global Config + type Config struct { Port int `json:"listenPort"` Organization string `json:"organization"` @@ -8,11 +12,23 @@ type Config struct { API string `json:"apiurl"` } +// variable for html template root +// generated from LoadHTMLToGin +var TMPL *template.Template + +// static served file type containing data and mimetype type StaticFile struct { Data string MimeType MimeType } +// parsed vmpath data (ie node/type/vmid) +type VMPath struct { + Node string + Type string + VMID string +} + // type used for templated