Compare commits

..
1 Commits
Author SHA1 Message Date
AverageMarcus 618a677164 Initial commit 2021-08-08 16:13:11 +01:00
2 changed files with 4 additions and 15 deletions
+1 -1
View File
@@ -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 .
+3 -14
View File
@@ -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(),
}