diff --git a/main.go b/main.go index 874e881..6cd6700 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "net" "net/http" "os" + "strings" "time" ) @@ -17,9 +18,10 @@ type echoResponse struct { Headers map[string][]string `json:"headers"` RemoteAddr string `json:"remoteAddr"` - ServerHostname string `json:"serverHostname"` - ServerIP string `json:"serverIP"` - DateTime time.Time `json:"dateTime"` + ServerHostname string `json:"serverHostname"` + ServerIP string `json:"serverIP"` + ServerEnv map[string]string `json:"serverEnv"` + DateTime time.Time `json:"dateTime"` } func main() { @@ -28,6 +30,14 @@ func main() { defer conn.Close() ipAddress := conn.LocalAddr().String() + serverEnv := map[string]string{} + for _, env := range os.Environ() { + if strings.HasPrefix(env, "ECHO_") { + parts := strings.Split(env, "=") + serverEnv[strings.TrimPrefix(parts[0], "ECHO_")] = parts[1] + } + } + http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { resp := echoResponse{ RequestPath: r.URL.String(), @@ -38,6 +48,7 @@ func main() { RemoteAddr: r.RemoteAddr, ServerHostname: hostname, ServerIP: ipAddress, + ServerEnv: serverEnv, DateTime: time.Now(), }