This repository is the official BE service for Fortress
.
├── cmd
│ └── server
├── docs
│ ├── adr
│ ├── changelog
│ ├── diagram
│ ├── specs
│ ├── docs.go
│ ├── swagger.json
│ └── swagger.yaml
├── migrations
│ ├── schemas
│ ├── seed
│ └── test_seed
├── pkg
│ ├── config
│ ├── constant
│ ├── contracts
│ ├── controller
│ ├── handler
│ ├── logger
│ ├── model
│ ├── mw
│ ├── request
│ ├── routes
│ ├── service
│ ├── store
│ ├── templates
│ ├── utils
│ ├── view
│ └── worker
├── CODEOWNERS
├── dbconfig.yml
├── devbox.json
├── devbox.lock
├── docker-compose.yml
├── Dockerfile
├── go.mod
├── go.sum
├── Makefile
├── README.md
└── tools.Dockerfile
- Create isolated shell using devbox
make shell
- Start Colima as container runtime
make colima-start
Related issue when initiating development environment first time using colima
- docker-credential-desktop not installed or not available in PATH
- tltr: Cheating by removing
credsStorein the~/.docker/config.json. Or installingosxkeychain
- tltr: Cheating by removing
-
Install Golang
-
Install Docker
- Set up source
Set up infras, install dependencies, etc.
make init
- Set up env
Create a file .env with these values:
DB_HOST="127.0.0.1"
DB_PORT="25432"
DB_USER="postgres"
DB_PASS="postgres"
DB_NAME="fortress_local"
DB_SSL_MODE="disable"
ALLOWED_ORIGINS="*"
ENV=dev
DEBUG=true
JWT_SECRET_KEY=JWTSecretKey
- Run source
make dev
The service starts with port 8080 as the default
- Feel free to pick any TODO for you from Board View
- Assign that item to your account
- Remember to update item’s status based on your working progress
Not Started: not started yetPlanned: working on this sprintIn Progress: still working onIn Review: Task done = PR has been merged todevelopbranch at leastComplete: Confirmation from the team that the TODO is finished
#### What's this PR do?
- [x] Add new routes for user
- [x] Add instruction for using docker-compose
#### What are the relevant Git tickets?
// Put in link to Git Issue
#### Screenshots (if appropriate)
// Use [Licecap](http://www.cockos.com/licecap/) to share a screencast gif.
#### Any background context you want to provide? (if appropriate)
- Is there a blog post?
- Does the knowledge base need an update?
- Does this add new dependencies which need to be added to?cmd/this folder contains the main application entry point files for the projectdocs/: contains Swagger documentation files generated by swaggomigrations/: contains seeds and SQL migration filesschemas/: contains DB schema migration filesseed/: contains seed files which will initialize DB with sets of dummy datatest-seed/: also seed files but for test DB
pkg/: contains core source code of serviceconfig/: contains configs for applicationhandler/: handling API requestslogger/: logging initial and functional methodsmodel/: DB model structsmw/: middlewarerequest/: API request modelsroutes/: API routing (see gin)service/: contains interaction with external services (google API, etc.)store/: data access layers, contains DB CRUD operations (see gorm)utils/: utility methodsview/: API view models
- Create new API
- Check out file
/pkg/routes/v1.goand explore the code flow to see how to create and handle an API - Remember to annotate handler functions with swaggo. Then run
make gen-swaggerto generate Swagger documentations
- New DB migration
Check out .sql files under /migrations to write a valid schema migration / seed file
- To apply new migration files, run
make migrate-up - To apply seed files, run
make seed-db - To apply new migration files for test DB, run
make migrate-test
Note: remember to run these 2 every time you pulling new code
make migrate-up
make migrate-test- DB repositories
Check out dirs under /pkg/store
- New API Implementation Steps
- Add the new route to
/pkg/routes/v1.go- Check if the new route is in a new group or an existing one
- Implement
interface IHandlerinpkg/handler/[name]/interface.go - Implement handling functions that takes a
*gin.Contextinpkg/handler/[name]/[name].go - Add Swagger doc to handler
- Add the sub handler to the main handler in
pkg/handler/handler.go
- Implement
- Check if the new route needs authentication
- Check if the new route needs authorization (permission)
- If a new permission is needed then define it in
pkg/model/permissions.go
- If a new permission is needed then define it in
- Check if the new route is in a new group or an existing one
- Add the new table
- Create new migration by
make migrate-new - Add seed file to
migrations/seed - Include the new seed file in
migrations/seed/seed.sql - Check if existing seed data needs modification (
roles.sql,permisions.sql, etc.) - Implement the model in
pkg/model - After the model is defined, implement the CRUD functions in
pkg/store- Implement
interface IStoreinpkg/store/[name]/interface.go - Implement the details in
pkg/store/[name]/[name].go - Add the sub store to the main store in
pkg/store/store.go
- Implement
- Create new migration by
- Glue the implemented handler and the implemented store
A big thanks to all who contributed to this project!
If you'd like to contribute, please contact us.