-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Frontend API boilerplate implementation (#34)
* Frontend API boilerplate implementation Auth service with env api keys Implemented JWT and updated auth handler * Updated to GIN, new Dockerfile and Makefile * Updated loggin as per recommendation * Removed leftover panics from the launcher * Updated readme --------- Co-authored-by: Nikolai Danylchyk <[email protected]> Co-authored-by: Mark Mandel <[email protected]>
- Loading branch information
1 parent
1378377
commit 89a4efd
Showing
13 changed files
with
868 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Building the application. | ||
FROM golang:1.19 as build | ||
|
||
WORKDIR /go/src/app | ||
COPY . . | ||
# In case of local .env being present | ||
RUN rm -rf .env | ||
|
||
RUN go mod download | ||
RUN go vet -v | ||
RUN go test -v | ||
RUN CGO_ENABLED=0 go build -o /go/bin/app | ||
|
||
# Copy bin into our base image. | ||
FROM gcr.io/distroless/static-debian11 | ||
COPY --from=build /go/bin/app / | ||
CMD ["/app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2023 Google LLC All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
BUILD_DIR=$(PWD)/build | ||
build: | ||
echo "Building frontend api service" | ||
mkdir -p ${BUILD_DIR} && GOOS=linux GOARCH=386 go build -o ${BUILD_DIR}/frontend-api main.go | ||
|
||
build-docker: | ||
echo "Building docker container" | ||
docker build . -t frontend-api | ||
|
||
clean: | ||
echo "Running cleanup" | ||
rm -rf ${BUILD_DIR}/ | ||
docker rmi -f frontend-api | ||
|
||
.PHONY: build build-docker clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Application API keys | ||
|
||
CLIENT_ID and SECRET_ID need to be generated and fetched from https://console.cloud.google.com/apis/credentials (OAuth 2.0 Client IDs) | ||
|
||
# For Local development | ||
|
||
Please create a .env file in the same with the following variables: | ||
|
||
```bash | ||
CLIENT_ID=<CLIENT_ID>.apps.googleusercontent.com | ||
CLIENT_SECRET=<CLIENT_SECRET> | ||
LISTEN_PORT=8081 | ||
CLIENT_LAUNCHER_PORT=8082 | ||
PROFILE_SERVICE=http://localhost:8080 | ||
PING_SERVICE=http://localhost:8083 | ||
JWT_KEY=<JWT_KEY> | ||
``` | ||
|
||
# Building locally | ||
|
||
`make build` | ||
|
||
Binary will be generated in the `build/` folder | ||
|
||
# Building container | ||
|
||
`make build-docker` | ||
|
||
To use container locally: | ||
|
||
`docker run --env-file .env -p 8081:8081 frontend-api` | ||
|
||
# Running in production | ||
|
||
Make sure the following environment variables are set | ||
|
||
```bash | ||
CLIENT_ID=<CLIENT_ID>.apps.googleusercontent.com | ||
CLIENT_SECRET=<CLIENT_SECRET> | ||
LISTEN_PORT=8081 | ||
CLIENT_LAUNCHER_PORT=8082 | ||
PROFILE_SERVICE=<PROFILE_SERVICE_ENDPOINT> | ||
PING_SERVICE=<PING_SERVICE_ENDPOINT> | ||
JWT_KEY=<JWT_KEY> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module github.com/googleforgames/global-multiplayer-demo/services/frontend-api | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/golang-jwt/jwt/v4 v4.5.0 | ||
github.com/joho/godotenv v1.5.1 | ||
golang.org/x/oauth2 v0.4.0 | ||
) | ||
|
||
require ( | ||
cloud.google.com/go/compute v1.14.0 // indirect | ||
cloud.google.com/go/compute/metadata v0.2.3 // indirect | ||
github.com/bytedance/sonic v1.8.1 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/gin-gonic/gin v1.9.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.11.2 // indirect | ||
github.com/goccy/go-json v0.10.0 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect | ||
github.com/leodido/go-urn v1.2.1 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.6 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.10 // indirect | ||
golang.org/x/arch v0.2.0 // indirect | ||
golang.org/x/crypto v0.6.0 // indirect | ||
golang.org/x/net v0.7.0 // indirect | ||
golang.org/x/sys v0.5.0 // indirect | ||
golang.org/x/text v0.7.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.