Step 3: embed.FS

This commit is contained in:
nemunaire 2024-05-29 14:21:23 +02:00
parent a01f4049d3
commit fe9b062c36

10
main.go
View File

@ -1,14 +1,14 @@
package main
import (
_ "embed"
"embed"
"io"
"log"
"net/http"
)
//go:embed index.html
var index []byte
//go:embed index.html style.css
var staticfiles embed.FS
func main() {
http.HandleFunc("GET /containers", func(w http.ResponseWriter, r *http.Request) {
@ -20,9 +20,7 @@ func main() {
}
})
http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.Write(index)
})
http.Handle("GET /", http.FileServer(http.FS(staticfiles)))
log.Fatal(http.ListenAndServe(":8080", nil))
}