From 21c84c9f6ec116b91bc5dc8751fea95c4a942268 Mon Sep 17 00:00:00 2001 From: Nulo Date: Mon, 23 Jan 2023 11:30:42 -0300 Subject: [PATCH] embed index.html --- gitea-ci/main.go | 7 ++++++- gitea-ci/static.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gitea-ci/static.go diff --git a/gitea-ci/main.go b/gitea-ci/main.go index 7868ddf..f6fb90f 100644 --- a/gitea-ci/main.go +++ b/gitea-ci/main.go @@ -7,8 +7,13 @@ import ( "strings" "gitea.nulo.in/Nulo/repro-run/gitea-ci/gitea" + + _ "embed" ) +//go:embed index.html +var index []byte + func main() { config := parseConfig() @@ -31,7 +36,7 @@ func main() { http.Handle("/webhook", webhook{config: config, gitea: g}) http.Handle("/logs/socket/", logWebsocket{}) - http.Handle("/", http.FileServer(http.Dir("."))) + http.Handle("/", staticRoute{file: index, mime: "text/html; charset=utf-8"}) log.Fatal(http.ListenAndServe(port, nil)) } diff --git a/gitea-ci/static.go b/gitea-ci/static.go new file mode 100644 index 0000000..d225f95 --- /dev/null +++ b/gitea-ci/static.go @@ -0,0 +1,13 @@ +package main + +import "net/http" + +type staticRoute struct { + file []byte + mime string +} + +func (s staticRoute) ServeHTTP(w http.ResponseWriter, req *http.Request) { + w.Header().Add("Content-Type", s.mime) + w.Write(s.file) +}