feat: added support for env vars
This commit is contained in:
parent
cea1ae23ac
commit
647c9a8b0c
11
main.go
11
main.go
@ -6,6 +6,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -19,6 +20,7 @@ type echoResponse struct {
|
||||
|
||||
ServerHostname string `json:"serverHostname"`
|
||||
ServerIP string `json:"serverIP"`
|
||||
ServerEnv map[string]string `json:"serverEnv"`
|
||||
DateTime time.Time `json:"dateTime"`
|
||||
}
|
||||
|
||||
@ -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(),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user