diff options
author | Julien Dessaux | 2025-01-22 00:46:49 +0100 |
---|---|---|
committer | Julien Dessaux | 2025-01-22 00:46:49 +0100 |
commit | 09885ef1e4b7610d05377596f02d08c5079c0434 (patch) | |
tree | 9c8322ea718f1eb721a4c685cb95386fa84bb797 /pkg/webui/states.go | |
parent | chore(webui): refactor login and session middleware handling (diff) | |
download | tfstated-09885ef1e4b7610d05377596f02d08c5079c0434.tar.gz tfstated-09885ef1e4b7610d05377596f02d08c5079c0434.tar.bz2 tfstated-09885ef1e4b7610d05377596f02d08c5079c0434.zip |
Diffstat (limited to 'pkg/webui/states.go')
-rw-r--r-- | pkg/webui/states.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/pkg/webui/states.go b/pkg/webui/states.go new file mode 100644 index 0000000..3633cb8 --- /dev/null +++ b/pkg/webui/states.go @@ -0,0 +1,29 @@ +package webui + +import ( + "html/template" + "net/http" + + "git.adyxax.org/adyxax/tfstated/pkg/database" + "git.adyxax.org/adyxax/tfstated/pkg/model" +) + +var statesTemplates = template.Must(template.ParseFS(htmlFS, "html/base.html", "html/states.html")) + +func handleStatesGET(db *database.DB) http.Handler { + type StatesData struct { + States []model.State + } + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Cache-Control", "no-store, no-cache") + + states, err := db.LoadStatesByPath() + if err != nil { + errorResponse(w, http.StatusInternalServerError, err) + return + } + render(w, statesTemplates, http.StatusOK, StatesData{ + States: states, + }) + }) +} |