Update README with build instructions for Windows and refactor agent handlers. Replace handleIndex with handleWeb in Serve method, and remove handleIndex function from handlers.go.

This commit is contained in:
2026-08-18 16:55:42 +03:00
parent f0515d7342
commit 4795c25da7
7 changed files with 458 additions and 10 deletions
+39
View File
@@ -0,0 +1,39 @@
package agent
import (
"embed"
"net/http"
"tea.chunkbyte.com/kato/go-worm/lib/helpers"
)
//go:embed web/index.html web/app.js
var webFS embed.FS
func (a *Agent) handleWeb(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
helpers.WriteError(w, http.StatusMethodNotAllowed, "method not allowed")
return
}
name := ""
contentType := ""
switch r.URL.Path {
case "/", "/index.html":
name = "web/index.html"
contentType = "text/html; charset=utf-8"
case "/app.js":
name = "web/app.js"
contentType = "text/javascript; charset=utf-8"
default:
helpers.WriteError(w, http.StatusNotFound, "endpoint not found")
return
}
data, err := webFS.ReadFile(name)
if err != nil {
helpers.WriteError(w, http.StatusInternalServerError, "ui asset missing")
return
}
w.Header().Set("Content-Type", contentType)
w.Header().Set("Cache-Control", "no-cache")
_, _ = w.Write(data)
}