Skip to content

MyMarvel/goLikes

Repository files navigation

My pet project on Golang

Allows users to add likes to other users.

I use Redis for NoSQL database, gin for web framework, gRPC as an alternative way to interact with this project, gomock for mocking framework.

Anything interesting?

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

How to use

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",
}

API Documentation

/likes/doLike

POST

Summary:

Adds a like to an account

Description:

Increments likes counter for a person in case the user didn't like them yet

Parameters
Name Located in Description Required Schema
Body body Params:
  • TargetAccount: The account name we like.
  • CurrentAccount: Our account (the person who likes)
Yes routes.doLikeParams
Responses
Code Description Schema
200 Example: {'likes': likesCount} string
208 Example: {'warning': 'Already liked'} string
400 Example: {'error': 'Error description'} string

/likes/getLikeCount

POST

Summary:

Get likes for an account

Description:

Returns amount of likes collected by a certain account

Parameters
Name Located in Description Required Schema
Body body Params:
  • TargetAccount: The account name we like
    Yes routes.getLikeCountParams
    Responses
    Code Description Schema
    200 Example: {'likes': likesCount} string
    400 Example: {'error': 'Error description'} string

    Models

    routes.doLikeParams

    Name Type Description Required
    currentAccount string Yes
    targetAccount string Yes

    routes.getLikeCountParams

    Name Type Description Required
    targetAccount string Yes

    Troubleshooting

    I am still new in Go world, so any improvements or suggestions are appreciated. Just submit a new issue here.

    About

    Allows users to add likes to other users

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published