Step 3: embed.FS
This commit is contained in:
parent
a01f4049d3
commit
fe9b062c36
10
main.go
10
main.go
@ -1,14 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
"embed"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed index.html
|
//go:embed index.html style.css
|
||||||
var index []byte
|
var staticfiles embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("GET /containers", func(w http.ResponseWriter, r *http.Request) {
|
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) {
|
http.Handle("GET /", http.FileServer(http.FS(staticfiles)))
|
||||||
w.Write(index)
|
|
||||||
})
|
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user