Added env route

This commit is contained in:
Stephen McQuay 2018-02-01 17:36:00 -08:00
parent 19adf9cb94
commit 54ced08b5a
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5

10
main.go
View File

@ -2,11 +2,14 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"log" "log"
"net/http" "net/http"
"os" "os"
) )
const version = "v0.0.7"
type v struct { type v struct {
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
V string `json:"version"` V string `json:"version"`
@ -21,12 +24,17 @@ func main() {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
r := v{ r := v{
Hostname: hn, Hostname: hn,
V: "v0.0.5", V: version,
} }
if err := json.NewEncoder(w).Encode(r); err != nil { if err := json.NewEncoder(w).Encode(r); err != nil {
log.Printf("json: %+v", err) log.Printf("json: %+v", err)
} }
}) })
http.HandleFunc("/env", func(w http.ResponseWriter, req *http.Request) {
for _, line := range os.Environ() {
fmt.Fprintf(w, "%v\n", line)
}
})
if err := http.ListenAndServe(":8080", nil); err != nil { if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatalf("listen and serve: %v", err) log.Fatalf("listen and serve: %v", err)
} }