Coder Social home page Coder Social logo

iredy_news_service's Introduction

About

This project is example of ToDo Service using clean design for gRPC microservices. Template for clean design you can find HERE

We have 4 main layer:

  1. Deliver layer
  2. Interactors (Use Cases)
  3. Repositories
  4. Domain

1 -> 2 -> 3 -> 4

First layer can use any other, Second layer can use only layers 3-4 and so on.

Domain

Models, UseCase behaviour (interfaces). !! NO IMPLEMENTATION !!

Repositories

Layer for getting data from any source. In example you can see postgres DB and test Mock implementation.

Interactors

Here we implement main logic of our service. Whole implementation depends on domain layer behaviour.

Delivery layer

After running of UseCases we should send result back to client. Here we can implement different clients types.
For example, gRPC client, REST client, CLI client.
So this layer doesn't depend on implementation of our core (interactors) and easy for testing.

Examples

Full example with JWT Auth microservice using this clean design you can find here - https://github.com/ekprog/grpc_auth_service

1. Compile gRPC files

protoc -I ./proto \
--go_out ./pkg/pb \
--go_opt paths=source_relative \
--go-grpc_out ./pkg/pb \
--go-grpc_opt paths=source_relative \
--grpc-gateway_out ./pkg/pb \
--grpc-gateway_opt paths=source_relative \
--openapiv2_out ./docs \
./proto/api/*.proto
protoc -I ./proto \
--go_out ./pkg/pb \
--go_opt paths=source_relative \
--go-grpc_out ./pkg/pb \
--go-grpc_opt paths=source_relative \
./proto/api/*.proto \
--experimental_allow_proto3_optional

1. Build docker

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./server
docker build -t api_gw .

2. Compile Events files

protoc -I ./proto \
--go_out ./pkg/pb \
--go_opt paths=source_relative \
./proto/events/**/*.proto

3. Build and Run

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./server
docker compose build
docker compose up

Deploy

docker compose --env-file .env up

iredy_news_service's People

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.