-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatic.go
More file actions
35 lines (29 loc) · 748 Bytes
/
static.go
File metadata and controls
35 lines (29 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package Form_Mailly_Go
import (
"embed"
"net/http"
"strconv"
)
//go:embed public/index.html
var publicFiles embed.FS
var indexHTML []byte
func init() {
b, err := publicFiles.ReadFile("public/index.html")
if err != nil {
panic(err) // Fail fast if the resource isn't embedded
}
indexHTML = b
}
func HomeHandler(response http.ResponseWriter, request *http.Request) {
if request.Method != http.MethodGet {
http.Error(response, "Method Not Allowed", http.StatusMethodNotAllowed)
return
}
response.Header().Set("Content-Type", "text/html; charset=utf-8")
response.Header().Set("Content-Length", strconv.Itoa(len(indexHTML)))
response.WriteHeader(http.StatusOK)
_, err := response.Write(indexHTML)
if err != nil {
return
}
}