summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2024-04-15 12:21:26 +0100
committerdiogo464 <[email protected]>2024-04-15 12:21:26 +0100
commitff207af453ef24534ea850b3d4436173960e31af (patch)
tree045eef3fe706e767659a42f3b26515b9f1459299
init
-rw-r--r--.gitignore1
-rw-r--r--Containerfile3
-rwxr-xr-xbuild.sh7
-rw-r--r--go.mod3
-rw-r--r--main.go29
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 @@
1FROM docker.io/alpine:latest
2COPY whoami /usr/bin/whoami
3ENTRYPOINT ["/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
3CGO_ENABLED=0 go build . || exit 1
4docker build -t git.d464.sh/code/whoami:latest -f Containerfile . || exit 1
5if [ "$PUSH" = "1" ]; then
6 docker push git.d464.sh/code/whoami:latest || exit 1
7fi
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..e24ebcb
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
1module git.d464.sh/code/whoami
2
3go 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 @@
1package main
2
3import (
4 "fmt"
5 "log"
6 "net/http"
7)
8
9func 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}