adds support for printing hostname
This commit is contained in:
parent
2f566d692a
commit
f13ff6199f
11
main.go
11
main.go
@ -4,16 +4,25 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type v struct {
|
type v struct {
|
||||||
|
Hostname string `json:"hostname"`
|
||||||
V string `json:"version"`
|
V string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
hn, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("hostname: %+v", err)
|
||||||
|
}
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
r := v{"v0.0.2"}
|
r := v{
|
||||||
|
Hostname: hn,
|
||||||
|
V: "v0.0.2",
|
||||||
|
}
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user