in staging/explorer/explorer.go [37:78]
func main() {
flag.Parse()
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Error getting hostname: %v", err)
}
links := []struct {
link, desc string
}{
{"/fs/", "Complete file system as seen by this container."},
{"/vars/", "Environment variables as seen by this container."},
{"/hostname/", "Hostname as seen by this container."},
{"/dns?q=google.com", "Explore DNS records seen by this container."},
{"/quit", "Cause this container to exit."},
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "<b> Kubernetes environment explorer </b><br/><br/>")
for _, v := range links {
fmt.Fprintf(w, `<a href="%v">%v: %v</a><br/>`, v.link, v.link, v.desc)
}
})
http.Handle("/fs/", http.StripPrefix("/fs/", http.FileServer(http.Dir("/"))))
http.HandleFunc("/vars/", func(w http.ResponseWriter, r *http.Request) {
for _, v := range os.Environ() {
fmt.Fprintf(w, "%v\n", v)
}
})
http.HandleFunc("/hostname/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, hostname)
})
http.HandleFunc("/quit", func(w http.ResponseWriter, r *http.Request) {
os.Exit(0)
})
http.HandleFunc("/dns", dns)
go log.Fatal(http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", *port), nil))
select {}
}