I use Redis for NoSQL database, gin for web framework, gRPC as an alternative way to interact with this project, gomock for mocking framework.
- cmd/main.go - main file
- internal/gRPCServer/gRPCServer.go - handlers for all services
- web/app/routes/routes.go - handlers for all routes
- internal/controllers/database.go - Redis database implementation
- test/account_test.go - an example of a unit test
- configs/default.yml - a config file
- Don't look at ./internal/mocks subfolder - it is generated automatically, as well as ./docs
- You can check swagger docs to see the public API of the project (run http://localhost:8080/swagger/index.html after the installation)
You should install and run a local redis server first (preferred port: 6379). Then:
git clone [email protected]:MyMarvel/goLikes.git
cd goLikes
Change services section in configs/default.yml file in case you want to disable the http part of the project and leave only the gRPC one. You can change ports for redis or a web server here too. Then execute:
make run
or
go run cmd/main.go
Send a POST request to http://localhost:8080/api/v1.0/likes/doLike with a json body like
{
"targetAccount": "Margulan Seissembai",
"currentAccount": "Nikita Petrov"
}
You'll get an updated amount of likes on this user, like
{
"likes": 1
}
Then send it again to observe the warning.
{
"warning": "Already liked"
}
To fetch amount of likes for a user without incrementing it, use http://localhost:8080/api/v1.0/likes/getLikeCount with a json body like:
{
"targetAccount": "Margulan Seissembai",
}
Adds a like to an account
Increments likes counter for a person in case the user didn't like them yet
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
Body | body | Params:
|
Yes | routes.doLikeParams |
Code | Description | Schema |
---|---|---|
200 | Example: {'likes': likesCount} |
string |
208 | Example: {'warning': 'Already liked'} |
string |
400 | Example: {'error': 'Error description'} |
string |
Get likes for an account
Returns amount of likes collected by a certain account
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
Body | body | Params:
|
Yes | routes.getLikeCountParams |
Code | Description | Schema |
---|---|---|
200 | Example: {'likes': likesCount} |
string |
400 | Example: {'error': 'Error description'} |
string |
Name | Type | Description | Required |
---|---|---|---|
currentAccount | string | Yes | |
targetAccount | string | Yes |
Name | Type | Description | Required |
---|---|---|---|
targetAccount | string | Yes |
I am still new in Go world, so any improvements or suggestions are appreciated. Just submit a new issue here.