Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54ced08b5a
|
||
|
|
19adf9cb94
|
||
|
|
79107389cc
|
||
|
|
bdab1c1346
|
||
|
|
f13ff6199f
|
@@ -2,22 +2,39 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const version = "v0.0.7"
|
||||||
|
|
||||||
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: 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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user