From cde7ce9346dc707fde49d7aebb55a13bc1b77626 Mon Sep 17 00:00:00 2001 From: "Lance R. Vick" Date: Wed, 1 Nov 2023 16:55:11 -0700 Subject: [PATCH] add go example --- examples/go_http_hello/Dockerfile | 9 +++++++++ examples/go_http_hello/main.go | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 examples/go_http_hello/Dockerfile create mode 100644 examples/go_http_hello/main.go diff --git a/examples/go_http_hello/Dockerfile b/examples/go_http_hello/Dockerfile new file mode 100644 index 0000000..dfec3ab --- /dev/null +++ b/examples/go_http_hello/Dockerfile @@ -0,0 +1,9 @@ +ARG GO_IMAGE=ocirep:go +FROM ${GO_IMAGE} as build +COPY . . +RUN cargo build main.go + +ARG CA_IMAGE=ocirep:ca-certificates +FROM scratch +COPY --from=${CA_IMAGE} / +COPY --from=build main . diff --git a/examples/go_http_hello/main.go b/examples/go_http_hello/main.go new file mode 100644 index 0000000..e2f0c6d --- /dev/null +++ b/examples/go_http_hello/main.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "net/http" +) + +func main() { + http.HandleFunc("/", HelloServer) + http.ListenAndServe(":8080", nil) +} + +func HelloServer(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:]) +}