Demo API template includes all the common packages and setup used for API development in this Company.
- Copy
.env.example
to.env
and update according to requirement. - Create
serviceAccountKey.json
file for firebase admin sdk. - To run
docker-compose up
(with default configuration will run at5000
and adminer runs at5001
)
Note: client will generate schema from swagger docs so, please follow these configurations
-
- use validate:"required" tag to insure generated fields/keys are not null/optional.
will be generated as
type User struct { Name string `json:"name" validate:"required"` }
elseinterface User { name: string; }
interface User { name?: string; }
- use validate:"required" tag to insure generated fields/keys are not null/optional.
-
- Using
// @Tags
for User and Admin Access endpoints- For easy navigation and understanding, utilize distinct @Tags values for endpoints accessible by users and admins. For instance,
- use:
// @Tags UserApi
for endpoints under /users accessible to regular users.// @Tags UserManagementApi
for endpoints under /users restricted to administrative access.
- Using
- Run
docker-compose exec web sh
- After running type
./__debug_bin cli
you will start cli application. - Choose the commands to run afterwards.
- To run
docker-compose up
( with default configuration will run at 5000 and adminer runs at 5001) - To run with setting up pre-commit hook
make start
( with default configuration will run at 5000 and adminer runs at 5001`)
This reduces hassle for developer to update IP in Cloud SQL during IP Change.
Implemented through docker image as follows
- Cloud SQL -> Google Proxy Docker Image -> Web App
ServiceAccountKey.json
requires Cloud SQL Read and Write PermissionDB_HOST_NAME
value in.env
is requiredDB_HOST=cloud-sql-proxy
instead ofIPV4
orDB_HOST_NAME
for development environmentDB_PORT
will be3306
by default
Command | Desc |
---|---|
make install |
installs goalngci-lint and change the hooks config |
make start |
setup pre-commit hook and runs the project |
make run |
runs the project |
make migrate-up |
runs migration up command |
make migrate-down |
runs migration down command |
make force |
Set particular version but don't run migration |
make goto |
Migrate to particular version |
make drop |
Drop everything inside database |
make create |
Create new migration file(up & down) |
make crud |
Create crud template |
make swag |
Run this command to generate swag docs |
- Dependency Injection (go-fx)
- Routing (gin web framework)
- Environment Files
- Logging (file saving on production) zap
- Middlewares (cors)
- Rate Limiting Middleware
- Middleware transaction
- Database Setup (mysql)
- Models Setup and Automigrate (gorm)
- Repositories
- Implementing Basic CRUD Operation
- CRUD Scaffold Generator
- Migration Runner Implementation
- Live code refresh
- Firebase basic setup.
- GCP Cloud Storage bucket setup.
- Twilio Basic setup.
- Gmail Api Setup.
For Debugging 🐞 Debugger runs at 5002
. Vs code configuration is at .vscode/launch.json
which will attach debugger to remote application.
For auto generate of CRUD(Create, ReaD, Update & Delete) api following informations are needed and will be asked in terminal:
-
resource-name: name of CRUD in upper camelCase. examples:Food,Puppy,ProductCategory etc.
-
resource-table-name: name of CRUD in lower snake case. examples:food,puppy,product_category etc.
-
plural-resource-table-name: plural name for the table going to be created. example: foods, puppies, product_categories.
-
plural-resource-name: plural name of CRUD in Upper camelCase. examples:Foods,Puppies,ProductCategories etc.