GithubHelp home page GithubHelp logo

tannpv / togo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kienmatu/togo

0.0 0.0 0.0 85 KB

A boilerplate for golang microservice using clean architecture

License: MIT License

Shell 0.57% Go 97.07% Dockerfile 2.36%

togo's Introduction

GOLANG TODOS APPLICATION

Technical stuff

  • Architecture: Clean architecture
  • Framework: Echo
  • ORM: Gorm
  • DB: Postgres
  • Deployment: Docker

Overview

  • Support JWT
  • Limit todos per user in a day
  • Unit tests & integration test

What next ?

  • Add role/permission based validation
  • Add missing tests
  • Implement your new features

How to run the code locally

Clone the project then:

Update .env file
PORT=8080
JWT_SECRET=B5bJHoI8aVLjAAeV
SIGNING_KEY=ABC
HASH_SALT=SJSHDFDS
TOKEN_TTL=86400
CONNECTION_URL=host=localhost user=postgres password=password1 dbname=todos port=5432
go run cmd/api/main.go
or by Docker

Update .env file (change host to postgresql)

#...
CONNECTION_URL=host=postgresql user=postgres password=password1 dbname=todos port=5432

RUN COMMAND:

docker-compose up -d

Then open postman or bash use curl:

Register:

curl --location --request POST 'http://localhost:8080/api/v1/auth/register' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "kiendinh",
    "password": "abc123",
    "limit": 2
}'

Login:

curl --location --request POST 'http://localhost:8080/api/v1/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "kiendinh",
    "password": "abc123"
}'

Take the token from login then.

Add todo:

curl --location --request POST 'http://localhost:8080/api/v1/todos/' \
--header 'Authorization: Bearer YOUR_TOKEN_HERE' \
--header 'Content-Type: application/json' \
--data-raw '{
    "content": "TEST TO DO 2x"
}'

Get all todos:

Public for all users

curl --location --request GET 'http://localhost:8080/api/v1/todos/'

Get user todos:

Get any user's todos with their id

curl --location --request GET 'http://localhost:8080/api/v1/todos/A_USER_ID' \
--header 'Authorization: Bearer YOUR_TOKEN_HERE'

TESTS

I just implemented some necessary test samples, we can add tests of handlers, usecases and another endpoints ...

UNIT TEST

Command:

go test ./...

INTEGRATION TEST

Command:

go test -v ./integration-tests

Conclusion

First time I created a new microservice with Go from scratch, It gave me a challenge but I did it, tried to remove the old mindset in another architecture then go to clean architecture. I love it ❤️ ❤️ .

togo's People

Contributors

kienmatu avatar lhtrieu87 avatar phi0411141 avatar nvcnvn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.