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 FROM golang:1.16-alpine AS builder
RUN apk update && apk add --no-cache git && apk add -U --no-cache ca-certificates RUN apk update && apk add --no-cache git && apk add -U --no-cache ca-certificates
WORKDIR /app/ WORKDIR /app/
ADD go.mod ./ ADD go.mod go.sum ./
RUN go mod download RUN go mod download
ADD . . ADD . .
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o echoserver . 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"
"net/http" "net/http"
"os" "os"
"strings"
"time" "time"
) )
@@ -18,10 +17,9 @@ type echoResponse struct {
Headers map[string][]string `json:"headers"` Headers map[string][]string `json:"headers"`
RemoteAddr string `json:"remoteAddr"` RemoteAddr string `json:"remoteAddr"`
ServerHostname string `json:"serverHostname"` ServerHostname string `json:"serverHostname"`
ServerIP string `json:"serverIP"` ServerIP string `json:"serverIP"`
ServerEnv map[string]string `json:"serverEnv"` DateTime time.Time `json:"dateTime"`
DateTime time.Time `json:"dateTime"`
} }
func main() { func main() {
@@ -30,14 +28,6 @@ func main() {
defer conn.Close() defer conn.Close()
ipAddress := conn.LocalAddr().String() 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) { http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
resp := echoResponse{ resp := echoResponse{
RequestPath: r.URL.String(), RequestPath: r.URL.String(),
@@ -48,7 +38,6 @@ func main() {
RemoteAddr: r.RemoteAddr, RemoteAddr: r.RemoteAddr,
ServerHostname: hostname, ServerHostname: hostname,
ServerIP: ipAddress, ServerIP: ipAddress,
ServerEnv: serverEnv,
DateTime: time.Now(), DateTime: time.Now(),
} }