Step 2: embed one file

This commit is contained in:
nemunaire 2024-05-29 12:12:13 +02:00
parent 36f5dde838
commit a01f4049d3

View File

@ -1,11 +1,15 @@
package main package main
import ( import (
_ "embed"
"io" "io"
"log" "log"
"net/http" "net/http"
) )
//go:embed index.html
var index []byte
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) {
rd, err := curl("/var/run/docker.sock", "GET", "http://d/v1.43/containers/json?all=true") rd, err := curl("/var/run/docker.sock", "GET", "http://d/v1.43/containers/json?all=true")
@ -16,7 +20,9 @@ func main() {
} }
}) })
http.Handle("GET /", http.FileServer(http.Dir("."))) http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.Write(index)
})
log.Fatal(http.ListenAndServe(":8080", nil)) log.Fatal(http.ListenAndServe(":8080", nil))
} }