This repository is official BE service for Mochi bot
- Go installed
- Docker installed
- Set up discord bot
- Owned a Metamask’s wallet. If not:
- Install Metamask on your browser
- After successful installation, you will be redirected to Metamask’s Getting started page. Follow the steps to create your own wallet
-
Set up source
Set up infras (db, redis), install dependencies, etc.
make setup -
Set up env
Update these variables inside
.env, How to get mnemonicCENTRALIZED_WALLET_PRIVATE_KEY=“your metamask wallet mnemonic” DISCORD_TOKEN='your discord bot token' -
Run source
make devYou should see the service starting with port 8200 as default
- Feel free to pick any TODO for you from Board View → Mochi → Backlog**
- Assign that item to your account
- Remember to update item’s status based on your working progress
Backlog: not started yetIn Progress: still working onIn Review: Task done = PR has been merged todevelopbranch at leastCompleted: Confirmation from the team that the TODO is completely finished
- When switching your TODO to
In Review, remember to fill these in
**What does this PR do?**
- [x] New API for updating ...
- [x] Update logic of ...
- [x] Fix error ...
**How to test**
- cURL
- Steps to test new logic
- etc.
**Flowchart** (optional)
Should have if the flow is complex
**Media** (Demo) (optional)
Attach images or demo videos
Can insert video URL in case the size exceeds github limit- Project structure
cmd/this folder contains the main application entry point files for the projectserver/main.go: Containing init functionmain()of the service. This function will be executed when we runmake dev- Other
main.gofiles (e.g.fetch-discord-users/main.go): Entry points to execute some functional jobs. k8s Cronjob will be set up to execute these jobs schedually
docs/: 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 servicecache/: caching initial and functional methodschain/: crypto chains’ initial and functional methodsconfig/: contains configs loaded from.envconstants/: constant variablesdiscordwallet/: methods to initialize & interact with crypto’s wallets (managed by Mochi)handler/: handling API requestsentities/: where mainly core business logic happens, invoked byhandlerandcmdjob/: contains initial andRun()as execution functions. These are invoked bymain()frommain.gofiles (exceptserver/main.go)logger/: logging initial and functional methodsmodel/: DB model structsrepo/: data access layer, contains DB CRUD operations (see gorm)request/&response/: API request & response modelsroutes/: API routing (see gin)services/: contains interaction with external services (coingecko API, binance API, etc.)util/: utility methods
- Modules references
-
Sample usecases
-
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
- Check out file
-
New DB migration
Check out
.sqlfiles under/migrationsto 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 - To apply new migration files, run
-
DB repositories
Check out dirs under
/pkg/repoNote: remember to runmake gen-mockto generate mocks for newstorefile
-
A big thanks to all who contributed to this project!
If you'd like to contribute, please check out the contributing guide.
- Reach us at discord.
- Discuss development in the #build-with-us channel.
