diff --git a/example/hydra-example/README.md b/examples/hydra-example/README.md similarity index 100% rename from example/hydra-example/README.md rename to examples/hydra-example/README.md diff --git a/example/hydra-example/docker-compose.yml b/examples/hydra-example/docker-compose.yml similarity index 100% rename from example/hydra-example/docker-compose.yml rename to examples/hydra-example/docker-compose.yml diff --git a/example/hydra-example/hydra.yml b/examples/hydra-example/hydra.yml similarity index 100% rename from example/hydra-example/hydra.yml rename to examples/hydra-example/hydra.yml diff --git a/examples/resource-server/.gitignore b/examples/resource-server/.gitignore new file mode 100644 index 0000000..6b72ac9 --- /dev/null +++ b/examples/resource-server/.gitignore @@ -0,0 +1,14 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +resource-server diff --git a/examples/resource-server/Dockerfile b/examples/resource-server/Dockerfile new file mode 100644 index 0000000..034b28c --- /dev/null +++ b/examples/resource-server/Dockerfile @@ -0,0 +1,23 @@ +FROM golang:1.22 AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . ./ + +RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -o /resource-server . + +FROM gcr.io/distroless/static-debian11:nonroot AS runner + +WORKDIR / + +COPY --from=builder --chown=nonroot:nonroot /resource-server /usr/bin/resource-server + +EXPOSE 8080 + +USER nonroot:nonroot + +ENTRYPOINT ["resource-server", "serve"] +CMD ["resource-server"] diff --git a/examples/resource-server/go.mod b/examples/resource-server/go.mod new file mode 100644 index 0000000..7a6eb56 --- /dev/null +++ b/examples/resource-server/go.mod @@ -0,0 +1,3 @@ +module github.com/baffao/examples/resource-server + +go 1.22 diff --git a/examples/resource-server/main.go b/examples/resource-server/main.go new file mode 100644 index 0000000..b79f7b1 --- /dev/null +++ b/examples/resource-server/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "encoding/json" + "log" + "net/http" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + requestDetails := map[string]string{ + "Method": r.Method, + "Path": r.URL.Path, + } + + authHeader := r.Header.Get("Authorization") + if authHeader != "" { + requestDetails["Authorization"] = authHeader + } + + jsonDetails, err := json.Marshal(requestDetails) + if err != nil { + log.Printf("Error marshaling JSON: %v", err) + return + } + + log.Println(string(jsonDetails)) + }) + + log.Fatal(http.ListenAndServe(":8080", nil)) +}