Giter Club home page Giter Club logo

go-iddd's Introduction

A sample project about implementing Domain-Driven Design and Hexagonal Architecture (Ports&Adapters) with Go!

This code is the basis for a series of blog posts:

Implementing Domain-Driven Design and Hexagonal Architecture with Go - Part 1

Implementing Domain-Driven Design and Hexagonal Architecture with Go - Part 2

Part 3 (about Hexagonal Architecture) is ongoing

The code those blog posts are about is frozen in this branch: freeze_blog-posts_1-3

Setup for local development

Start Docker container(s)

Run docker-compose up -d in the project root.

Environment configuration

To be able to start the service

Create local.env file in the project root (.env files is gitignored there) with following contents and replace $PathToProjectRoot$ with the path to the root of the go-iddd project sources.

POSTGRES_DSN=postgresql://goiddd:password123@localhost:15432/goiddd_local?sslmode=disable
POSTGRES_MIGRATIONS_PATH_CUSTOMER=$PathToProjectRoot$/go-iddd/service/customeraccounts/infrastructure/postgres/database/migrations
GRPC_HOST_AND_PORT=localhost:5566
REST_HOST_AND_PORT=localhost:8085
REST_GRPC_DIAL_TIMEOUT=3
SWAGGER_FILE_PATH_CUSTOMER=$PathToProjectRoot$/go-iddd/src/customeraccounts/infrastructure/adapter/rest
To be able to run the tests

Create test.env file in the project root (.env files is gitignored there) with following contents and replace $PathToProjectRoot$ with the path to the root of the go-iddd project sources.

POSTGRES_DSN=postgresql://goiddd:password123@localhost:15432/goiddd_test?sslmode=disable
POSTGRES_MIGRATIONS_PATH_CUSTOMER=$PathToProjectRoot$/go-iddd/src/customeraccounts/infrastructure/adapter/postgres/database/migrations
GRPC_HOST_AND_PORT=localhost:5566
REST_HOST_AND_PORT=localhost:8085
REST_GRPC_DIAL_TIMEOUT=3
SWAGGER_FILE_PATH_CUSTOMER=$PathToProjectRoot$/go-iddd/src/customeraccounts/infrastructure/adapter/rest
To run HTTP requests with GoLand's (IntelliJ) new built-in HTTP client

Create a customer.http file in the project root (.http files are gitignored there) with following contents.

### Register a Customer
POST http://localhost:8085/v1/customer
Accept: */*
Cache-Control: no-cache
Content-Type: application/json

{
  "emailAddress": "[email protected]",
  "familyName": "Doe",
  "givenName": "John"
}

> {% client.global.set("id", response.body.id); %}

### Confirm a Customer's email address
PUT http://localhost:8085/v1/customer/{{id}}/emailaddress/confirm
Accept: */*
Cache-Control: no-cache
Content-Type: application/json

{
  "confirmationHash": "0acf14bbeaf0b9c6ef8e39d7f9254336"
}

### Change a Customer's email address
PUT http://localhost:8085/v1/customer/{{id}}/emailaddress
Accept: */*
Cache-Control: no-cache
Content-Type: application/json

{
  "emailAddress": "[email protected]"
}

### Change a Customer's name
PUT http://localhost:8085/v1/customer/{{id}}/name
Accept: application/json
Cache-Control: no-cache
Content-Type: application/json

{
  "givenName": "Joana",
  "familyName": "Doe"
}

### Delete a Customer
DELETE http://localhost:8085/v1/customer/{{id}}
Accept: application/json
Cache-Control: no-cache
Content-Type: application/json

### Retrieve a Customer View
GET http://localhost:8085/v1/customer/{{id}}
Accept: application/json
Cache-Control: no-cache
Content-Type: application/json

### Get the Swagger documentation
GET http://localhost:8085/v1/customer/swagger.json

###

Attention

The ConfirmEmailAddress request does not work without changes - the confirmationHash needs to be adapted. You can find it in the CustomerRegistered event in the eventstore DB table. For security reasons the response of the Register request does not return the hash (it must only be sent to the Customer via email ;-)

Start the service (gRPC and REST)

Via Terminal
  1. Source the local.env file in your terminal, e.g. source dev/local.env or set the env vars in a different way
  2. In the project root run go run service/cmd/grpc/main.go
Via GoLand
  1. Create a build configuration for service/cmd/grpc/main.go
  2. I suggest using the EnvFile GoLand plugin and add the local.env file in the build configuration

go-iddd's People

Contributors

antonstoeckl avatar anton-stoeckl-mw avatar

Watchers

James Cloos 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.