meetup-golang-2024-demo/main.go

29 lines
552 B
Go

package main
import (
_ "embed"
"io"
"log"
"net/http"
)
//go:embed index.html
var index []byte
func main() {
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")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
io.Copy(w, rd)
}
})
http.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.Write(index)
})
log.Fatal(http.ListenAndServe(":8080", nil))
}