add a bunch of comments to important code

This commit is contained in:
2025-11-18 19:36:05 +00:00
parent 338ea3342e
commit b86be4c749
6 changed files with 47 additions and 26 deletions

View File

@@ -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 <select>
type Select struct {
ID string
@@ -27,8 +43,6 @@ type Option struct {
Display string
}
type RequestType int
type RequestContext struct {
Cookies map[string]string
}

View File

@@ -20,15 +20,7 @@ import (
"github.com/tdewolff/minify/v2"
)
var TMPL *template.Template
var Global Config
type VMPath struct {
Node string
Type string
VMID string
}
// get config file from configPath
func GetConfig(configPath string) Config {
content, err := os.ReadFile(configPath)
if err != nil {
@@ -42,6 +34,7 @@ func GetConfig(configPath string) Config {
return config
}
// initialize minifier using the meta types specified
func InitMinify() *minify.M {
m := minify.New()
for _, v := range MimeTypes {
@@ -125,7 +118,7 @@ func LoadHTMLToGin(engine *gin.Engine, html map[string]StaticFile) *template.Tem
},
}
tmpl := template.Must(root, LoadAndAddToRoot(engine.FuncMap, root, html))
engine.SetHTMLTemplate(tmpl)
engine.SetHTMLTemplate(root)
return tmpl
}