diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Containerfile | 3 | ||||
| -rwxr-xr-x | build.sh | 7 | ||||
| -rw-r--r-- | go.mod | 3 | ||||
| -rw-r--r-- | main.go | 29 |
5 files changed, 43 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aec4ee9 --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1 @@ | |||
| /whoami | |||
diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..d47dd69 --- /dev/null +++ b/Containerfile | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | FROM docker.io/alpine:latest | ||
| 2 | COPY whoami /usr/bin/whoami | ||
| 3 | ENTRYPOINT ["/usr/bin/whoami"] | ||
diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..e39ad0d --- /dev/null +++ b/build.sh | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | #!/usr/bin/sh | ||
| 2 | |||
| 3 | CGO_ENABLED=0 go build . || exit 1 | ||
| 4 | docker build -t git.d464.sh/code/whoami:latest -f Containerfile . || exit 1 | ||
| 5 | if [ "$PUSH" = "1" ]; then | ||
| 6 | docker push git.d464.sh/code/whoami:latest || exit 1 | ||
| 7 | fi | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | module git.d464.sh/code/whoami | ||
| 2 | |||
| 3 | go 1.21.9 | ||
| @@ -0,0 +1,29 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "log" | ||
| 6 | "net/http" | ||
| 7 | ) | ||
| 8 | |||
| 9 | func main() { | ||
| 10 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
| 11 | log.Print(r) | ||
| 12 | fmt.Fprintf(w, "Method: %v\n", r.Method) | ||
| 13 | fmt.Fprintf(w, "URL: %v\n", r.URL) | ||
| 14 | fmt.Fprintf(w, "Proto: %v\n", r.Proto) | ||
| 15 | fmt.Fprintf(w, "Header:\n") | ||
| 16 | for key, value := range r.Header { | ||
| 17 | fmt.Fprintf(w, "\t%v: ", key) | ||
| 18 | for _, v := range value { | ||
| 19 | fmt.Fprintf(w, "'%v' ", v) | ||
| 20 | } | ||
| 21 | fmt.Fprintf(w, "\n") | ||
| 22 | } | ||
| 23 | fmt.Fprintf(w, "RemoteAddr: %v\n", r.RemoteAddr) | ||
| 24 | w.WriteHeader(http.StatusOK) | ||
| 25 | }) | ||
| 26 | if err := http.ListenAndServe(":8000", nil); err != nil { | ||
| 27 | log.Fatalf("failed to listen and serve: %v", err) | ||
| 28 | } | ||
| 29 | } | ||
