Compare commits
1
Commits
main
..
618a677164
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
618a677164 |
+1
-1
@@ -1,7 +1,7 @@
|
||||
FROM golang:1.16-alpine AS builder
|
||||
RUN apk update && apk add --no-cache git && apk add -U --no-cache ca-certificates
|
||||
WORKDIR /app/
|
||||
ADD go.mod ./
|
||||
ADD go.mod go.sum ./
|
||||
RUN go mod download
|
||||
ADD . .
|
||||
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o echoserver .
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -18,10 +17,9 @@ type echoResponse struct {
|
||||
Headers map[string][]string `json:"headers"`
|
||||
RemoteAddr string `json:"remoteAddr"`
|
||||
|
||||
ServerHostname string `json:"serverHostname"`
|
||||
ServerIP string `json:"serverIP"`
|
||||
ServerEnv map[string]string `json:"serverEnv"`
|
||||
DateTime time.Time `json:"dateTime"`
|
||||
ServerHostname string `json:"serverHostname"`
|
||||
ServerIP string `json:"serverIP"`
|
||||
DateTime time.Time `json:"dateTime"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -30,14 +28,6 @@ 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(),
|
||||
@@ -48,7 +38,6 @@ func main() {
|
||||
RemoteAddr: r.RemoteAddr,
|
||||
ServerHostname: hostname,
|
||||
ServerIP: ipAddress,
|
||||
ServerEnv: serverEnv,
|
||||
DateTime: time.Now(),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user