HoneyComb

HoneyComb is a web interface for managing FreeBSD jails and Bhyve VMs.
Log | Files | Refs | README | LICENSE

commit a35abd2c240ad3d1ef8f6a6caa90f168646a49e6
parent 084cfd9bf5572652191d729cdda5f05be94ffd37
Author: Tyler Clark <tyler.clark@foxide.xyz>
Date:   Sun, 28 Dec 2025 23:17:17 -0500

Adding dynamic button generation.

This patch adds the ability to dynamically generate buttons based around the values of an array,
eventaully, this is what will be generating different things for users to use for interacting with jails and VMs.

Diffstat:
MMakefile | 5++++-
Acmd/buttons.go | 10++++++++++
Mcmd/main.go | 30++++++++++++++++++++++++------
Mstatic/buttons.html | 2+-
Mstatic/index.html | 5++++-
5 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,5 +1,8 @@ ALL: - go124 build cmd/main.go + go124 build cmd/main.go cmd/buttons.go + +test: + go124 build cmd/main.go cmd/buttons.go cmd/test.go clean: rm main diff --git a/cmd/buttons.go b/cmd/buttons.go @@ -0,0 +1,10 @@ +package main + +import ( + "html/template" + "net/http" +) +func render_ui(w http.ResponseWriter, r *http.Request, j_name string) { + tmpl := template.Must(template.ParseFiles("static/buttons.html")) + tmpl.Execute(w, map[string]string{"j_name": j_name}) +} diff --git a/cmd/main.go b/cmd/main.go @@ -10,7 +10,7 @@ import ( type naming func(num int) string func get_name(n int) (jail string) { - j_names := [2]string{"ca", "test-jail"} + j_names := []string{"ca", "test-jail"} jail = j_names[n] return } @@ -66,31 +66,49 @@ func handler(w http.ResponseWriter, r *http.Request, random string) { /* This function handles rendering the buttons for the * * various jails on the system, will be extented for * * VMs as well. */ +/* func render_ui(w http.ResponseWriter, r *http.Request, j_name string) { tmpl := template.Must(template.ParseFiles("static/buttons.html")) tmpl.Execute(w, map[string]string{"j_name": j_name}) } +*/ func main() { - test := "Tyler" - jail_name := "ca" + //test := "Tyler" + test := []string{"Tyler", "Elizabeth", "Allison", "Riven"} + jail_name := []string{"ca", "test-jail"} http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) { - handler(w, r, test) + handler(w, r, test[1]) }) /* Start Jails */ http.HandleFunc("/start", func(w http.ResponseWriter, r *http.Request) { - j_start(w, r, jail_name) + j_start(w, r, jail_name[0]) }) /* Stop Jails */ http.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) { - j_stop(w, r, jail_name) + j_stop(w, r, jail_name[0]) }) + /* Build the UI */ + http.HandleFunc("/buttons", func(w http.ResponseWriter, r *http.Request) { + render_ui(w, r, jail_name[0]) + render_ui(w, r, jail_name[1]) + }) + + /* + * Commenting this for a test, the below one does work, + * but needs improvement + * + * http.Handle("/", http.FileServer(http.Dir("./static"))) + */ + /* Function for rendering the landing page */ http.Handle("/", http.FileServer(http.Dir("./static"))) + + /* Functions for rendering buttons clicks */ http.HandleFunc("/status", j_status) http.HandleFunc("/hello", helloHandler) http.ListenAndServe(":8080", nil) diff --git a/static/buttons.html b/static/buttons.html @@ -1,4 +1,4 @@ -{{ define "genButton"}} +{{ block "genButton" . }} <button hx-get="/start" hx-target="#result" hx-swap="innerHTML">Start {{ .j_name }}</button><br /> <button hx-get="/stop" hx-target="#result" hx-swap="innerHTML">Stop {{ .j_name }}</button><br /> {{end}} diff --git a/static/index.html b/static/index.html @@ -7,12 +7,15 @@ <h1>HTMX + Go Demo</h1> <div id="buttons"></div> <button hx-get="/test" hx-target="#result" hx-swap="innerHTML">Test Button</button> + <!-- + Probably don't need these buttons anymore <button hx-get="/start" hx-target="#result" hx-swap="innerHTML">Start Jail</button><br /> <button hx-get="/stop" hx-target="#result" hx-swap="innerHTML">Stop Jail</button><br /> + --> <button hx-get="/status" hx-target="#result" hx-swap="innerHTML">Jail Status</button><br /> <button hx-get="/buttons" hx-target="#result" hx-swap "innerHTML">Generate Button</button><br /> <div id="result"> - {{template "genButton"}} + {{ template "genButtons" . }} </div> </body> </html>