Compare commits
1
Commits
main
..
618a677164
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
618a677164 |
+1
-1
@@ -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 .
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ type echoResponse struct {
|
|||||||
|
|
||||||
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user