37 lines
683 B
Go
37 lines
683 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
|
|
_ "embed"
|
|
)
|
|
|
|
var index string = ""
|
|
|
|
func SendIndex(wr http.ResponseWriter, req *http.Request) {
|
|
if index == "" {
|
|
bytes, err := os.ReadFile("index.html")
|
|
if err != nil {
|
|
http.Error(wr, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
index = string(bytes)
|
|
}
|
|
|
|
resp := http.Response{
|
|
Body: io.NopCloser(bytes.NewBufferString(index)),
|
|
StatusCode: 200,
|
|
}
|
|
resp.Header = http.Header{}
|
|
resp.Header.Add("Content-Type", "text/html")
|
|
resp.Header.Add("Server", "astra")
|
|
req.Response = &resp
|
|
copyHeader(wr.Header(), resp.Header)
|
|
wr.WriteHeader(resp.StatusCode)
|
|
flush(wr)
|
|
copyBody(wr, resp.Body)
|
|
}
|