Skip to content

Commit

Permalink
chore: add resource server example
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Mar 28, 2024
1 parent a03c058 commit 5a1df35
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions examples/resource-server/.gitignore
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions examples/resource-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
3 changes: 3 additions & 0 deletions examples/resource-server/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/baffao/examples/resource-server

go 1.22
31 changes: 31 additions & 0 deletions examples/resource-server/main.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 5a1df35

Please sign in to comment.