From ff207af453ef24534ea850b3d4436173960e31af Mon Sep 17 00:00:00 2001 From: diogo464 Date: Mon, 15 Apr 2024 12:21:26 +0100 Subject: init --- .gitignore | 1 + Containerfile | 3 +++ build.sh | 7 +++++++ go.mod | 3 +++ main.go | 29 +++++++++++++++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 .gitignore create mode 100644 Containerfile create mode 100755 build.sh create mode 100644 go.mod create mode 100644 main.go 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 @@ +FROM docker.io/alpine:latest +COPY whoami /usr/bin/whoami +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 @@ +#!/usr/bin/sh + +CGO_ENABLED=0 go build . || exit 1 +docker build -t git.d464.sh/code/whoami:latest -f Containerfile . || exit 1 +if [ "$PUSH" = "1" ]; then + docker push git.d464.sh/code/whoami:latest || exit 1 +fi diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e24ebcb --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.d464.sh/code/whoami + +go 1.21.9 diff --git a/main.go b/main.go new file mode 100644 index 0000000..e37cc2e --- /dev/null +++ b/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + log.Print(r) + fmt.Fprintf(w, "Method: %v\n", r.Method) + fmt.Fprintf(w, "URL: %v\n", r.URL) + fmt.Fprintf(w, "Proto: %v\n", r.Proto) + fmt.Fprintf(w, "Header:\n") + for key, value := range r.Header { + fmt.Fprintf(w, "\t%v: ", key) + for _, v := range value { + fmt.Fprintf(w, "'%v' ", v) + } + fmt.Fprintf(w, "\n") + } + fmt.Fprintf(w, "RemoteAddr: %v\n", r.RemoteAddr) + w.WriteHeader(http.StatusOK) + }) + if err := http.ListenAndServe(":8000", nil); err != nil { + log.Fatalf("failed to listen and serve: %v", err) + } +} -- cgit