hw/main.go

46 lines
941 B
Go
Raw Normal View History

2018-01-09 16:26:12 -08:00
package main
import (
"encoding/json"
2018-02-01 17:36:00 -08:00
"fmt"
2018-01-09 16:26:12 -08:00
"log"
"net/http"
2018-01-10 09:49:42 -08:00
"os"
2018-01-09 16:26:12 -08:00
)
const version = "v0.0.9"
2018-02-01 17:36:00 -08:00
2018-01-09 16:26:12 -08:00
type v struct {
2018-01-10 09:49:42 -08:00
Hostname string `json:"hostname"`
V string `json:"version"`
2018-01-09 16:26:12 -08:00
}
func main() {
2018-01-10 09:49:42 -08:00
hn, err := os.Hostname()
if err != nil {
log.Fatalf("hostname: %+v", err)
}
2018-01-09 16:26:12 -08:00
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
2018-01-10 09:49:42 -08:00
r := v{
Hostname: hn,
2018-02-01 17:36:00 -08:00
V: version,
2018-01-10 09:49:42 -08:00
}
2018-01-09 16:26:12 -08:00
if err := json.NewEncoder(w).Encode(r); err != nil {
log.Printf("json: %+v", err)
}
})
2018-02-01 17:36:00 -08:00
http.HandleFunc("/env", func(w http.ResponseWriter, req *http.Request) {
for _, line := range os.Environ() {
fmt.Fprintf(w, "%v\n", line)
}
})
2018-02-07 13:58:15 -08:00
http.HandleFunc("/live", health)
http.HandleFunc("/ready", health)
2018-01-09 16:26:12 -08:00
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatalf("listen and serve: %v", err)
}
}
2018-02-07 13:58:15 -08:00
func health(w http.ResponseWriter, req *http.Request) {}