Welcome to the Lotof Sample Gateway project! This project provides a structure to generate, build, and run a GraphQL server using gqlgen and Docker for containerization. Below you'll find a comprehensive guide to get started with this project.
Before you begin, ensure you have the following installed on your machine:
- Go (version 1.23 or later)
- Docker
- Docker Compose
The project uses a Makefile to automate common tasks. Below are the available make targets and their functionalities:
- Description: Generates the necessary Go files for gqlgen, gRPC, and runs the server.
- Commands:
- Executes the
gqlgenandgrpcgentargets. - Starts the server using
make run.
- Executes the
- Description: Generates the Go code required for your GraphQL server.
- Commands:
- Executes
$(GQLGEN) generateto generate GraphQL server code. - Cleans up dependencies with
go mod tidy.
- Executes
- Description: Generates Go stubs for gRPC services.
- Commands:
- Uses
$(PROTOC)with pluginsprotoc-gen-goandprotoc-gen-go-grpc. - Places the generated files in
./internal/core/grpc/generated.
- Uses
- Description: Runs the GraphQL server.
- Commands:
- Executes
go run ./cmd/server/main.goto start the server.
- Executes
- Description: Builds a Docker image for the development environment.
- Commands:
- Builds Docker image using
dev.dockerfileand names itgateway-dev.
- Builds Docker image using
- Description: Builds a Docker image for the production environment.
- Commands:
- Builds Docker image using
main.dockerfileand names itgateway-prod.
- Builds Docker image using
- Description: Starts the services defined in
docker-compose.yml. - Commands:
- Runs
$(DOCKER_COMPOSE) up -dto start services in detached mode.
- Runs
- Description: Stops and removes the services defined in
docker-compose.yml. - Commands:
- Runs
$(DOCKER_COMPOSE) downto stop the services.
- Runs
- Description: Cleans up generated files.
- Commands:
- Removes the files in
internal/core/grpc/generatedand GraphQL-related generated files.
- Removes the files in
-
Clone the repository:
git clone https://github.com/pieceowater-dev/lotof.sample.gtw.git cd lotof.sample.gtw -
Install dependencies:
go mod tidy-
Generate GraphQL files and start the server:
make all
-
(Optional) To build Docker images for development or production:
make build
-
(Optional) To manage Docker services:
make compose-up # Start services make compose-down # Stop services
- Customize
Dockerfileas needed for your project's specific requirements. - The server entry point is at
./cmd/server/main.go.
This project is licensed under the MIT License - see the LICENSE file for details.