GithubHelp home page GithubHelp logo

go-poc's Introduction

commit stage Go Report Card

Go POCs

This repository holds proof of concepts related to Go web applications. All concepts applied will be documented here. The applied concepts will be documented on the application itself, using go docs.

Architecture overview

The architecture presented here is aimed toward the hexagonal architecture. To achieve it, interfaces are used as much as possible to isolate every external resource from the domain. This leads to a lot of indirection, which is resolved by a dependency injection container. FX was chosen to fulfil this purpose.

Dependency injection

As mentioned earlier, FX is used to resolve and inject all dependencies in this application. FX is built with two basic concepts: construction and invocation.

This application delegates the responsibility of defining all constructors and invokables from a package itself. Each package that requires DI has a module, declaring the constructors and invokables. Outer packages will import inner packages and compose their own module with the imported modules. This is propagated up to the main application modules. The main application module is then used to run the application.

Constructors

Constructors are used to building a given dependency. FX uses registered constructors to resolve the dependencies from other constructors.

Invokables

Invokables are functions called after all dependencies are resolved. FX calls these with the resulting dependencies. They are used to kickstart the application and perform actions that are typically executed once in the application lifetime. Their use includes, but is not limited to opening database connections, registering HTTP routes.

Interface resolution

One of the most common patterns in go is accepting interfaces and return structs. This, along with the client-side interface definition, has the power to make testing extremely simple. The downside is that it creates a lot of indirection.

FX allows us to resolve this indirection by mapping interfaces to implementations. Because this application is composed of modules that compose other modules, resolving this mapping is pretty straightforward and should be done ate the module importing both client and provider.

With this approach, adapters are completely isolated and are consumed - through the ports - by the use cases.

See the whole user module for complete examples.

Ports and Adapters

A quick reference for the ports and adapters present on the application can be found bellow. Detailed documentation is present on their packages.

Protobuffers

Protocol buffers are stores in the protos directory and are managed by Buf. See their documentation for details.

GRPC (server)

The GRPC server module contains only the server initialization and is not related to the application itself. Each port (eg. handlers, etc...) will be defined on the GRPC module of their domain, such as the Order module.

Kafka

The Kafka provides the Kafka config struct to producers and consumers.

HTTP

HTTP is handled by Fiber. The main server setup can be found on Fiber's module. Handlers (i.e. adapters) can be found on the HTTP package of each domain, such as the Order handler and HTTP module.

Tests (integration)

Integration tests are organized either by domain or by the integration they are testing. E.g. producer-consumer test, grpc test.

Configs

Configs are managed by Viper. They are loaded by FX at the application's startup. The Viper struct is also registered in the container and can be used as a service if needed.

The application loads and registers configs as any other dependency: in the FX lifecycle. As with other modules, the configs module can be nested and combined to form the main configs module. See configs package for details.

go-poc's People

Contributors

dependabot[bot] avatar renovate-bot avatar renovate[bot] avatar thefuga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

khorevaa

go-poc's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update module buf.build/gen/go/thefuga/go-poc/grpc/go to v1.4.0-20220711145547-e6891151c45d.1
  • Update module buf.build/gen/go/thefuga/go-poc/protocolbuffers/go to v1.34.1-20220711145547-e6891151c45d.1
  • Update module github.com/spf13/viper to v1.19.0
  • Update module go.uber.org/fx to v1.22.0
  • Update module google.golang.org/grpc to v1.64.0
  • Update actions/cache action to v4
  • Update golangci/golangci-lint-action action to v6
  • Update module github.com/confluentinc/confluent-kafka-go to v2
  • Update module github.com/onsi/ginkgo to v2
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
  • confluentinc/cp-zookeeper 7.2.0
  • confluentinc/cp-server 7.2.0
  • confluentinc/cp-schema-registry 7.2.0
  • cnfldemos/cp-server-connect-datagen 0.5.0-6.2.0
  • confluentinc/cp-enterprise-control-center 7.2.0
  • confluentinc/cp-ksqldb-server 7.2.0
  • confluentinc/cp-ksqldb-cli 7.2.0
  • confluentinc/ksqldb-examples 7.2.0
  • confluentinc/cp-kafka-rest 7.2.0
github-actions
.github/workflows/commit-stage.yml
  • actions/checkout v4
  • actions/setup-go v5
  • golangci/golangci-lint-action v3
  • actions/checkout v4
  • actions/setup-go v5
  • actions/cache v3
  • actions/checkout v4
  • actions/setup-go v5
  • actions/cache v3
  • actions/upload-artifact v4
  • actions/checkout v4
  • actions/setup-go v5
  • actions/cache v3
  • actions/checkout v4
  • actions/setup-go v5
  • actions/cache v3
gomod
go.mod
  • go 1.18
  • buf.build/gen/go/thefuga/go-poc/grpc/go v1.3.0-20220711145547-e6891151c45d.2@e6891151c45d
  • buf.build/gen/go/thefuga/go-poc/protocolbuffers/go v1.32.0-20220711145547-e6891151c45d.1@e6891151c45d
  • github.com/confluentinc/confluent-kafka-go v1.9.1
  • github.com/gofiber/fiber/v2 v2.52.0
  • github.com/onsi/ginkgo v1.16.5
  • github.com/onsi/gomega v1.19.0
  • github.com/spf13/viper v1.11.0
  • go.uber.org/fx v1.20.1
  • google.golang.org/grpc v1.60.1

  • Check this box to trigger a request for Renovate to run again on this repository

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.