adapters

package
v0.0.0-...-5ff842d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 11 Imported by: 0

README

This folder contains adapters for the interfaces (ports) defined in the orders module.

Both driven and driver adapters can be found here:

For example:

  • in_memory_order_repo.go - implements the OrderRepository interface using a basic in-memory map
  • grpc_order_service.go - exposes the OrderService interface as a grpc service
  • http_order_service.go - exposes the OrderService interface as HTTP endpoints

NOTE: Different implementations of hexagonal architecture may group adapter implementations by technology, not by domain.

  • For example, gin_order_service.go might go in the gin module, instead of in here in the orders module. It's mostly personal preference.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GinOrderService

type GinOrderService struct {
	// contains filtered or unexported fields
}

Adapter for the OrderService, exposes the service's endpoints as HTTP routes on a gin server

func NewGinAdapter

func NewGinAdapter(svc orders.OrderService, logger *zap.SugaredLogger) *GinOrderService

func (*GinOrderService) RegisterRoutes

func (gos *GinOrderService) RegisterRoutes(engine *gin.Engine)

type MockOrderRepo

type MockOrderRepo struct {
	mock.Mock
}

Implementation of OrderRepository used in unit tests TODO: Look into https://github.com/vektra/mockery for auto-generating mock objects

func (*MockOrderRepo) GetMany

func (m *MockOrderRepo) GetMany() ([]orders.Order, error)

func (*MockOrderRepo) GetOne

func (m *MockOrderRepo) GetOne(id string) (*orders.Order, error)

func (*MockOrderRepo) Save

func (m *MockOrderRepo) Save(order *orders.Order) error

type PostgresOrderRepo

type PostgresOrderRepo struct {
	// contains filtered or unexported fields
}

Implementation of OrderRepository using a postgres database as the storage mechanism.

NOTE: this repo does not bootstrap the tables it uses, look at postgres/migrations.go for the migration which creates the order table. In a bigger project, each domain module would bootstrap its own tables when the adapter is initialized - using a different schema for each domain module.

func NewPostgresOrderRepo

func NewPostgresOrderRepo(conn *pgx.Conn, logger *zap.SugaredLogger) *PostgresOrderRepo

func (*PostgresOrderRepo) GetMany

func (por *PostgresOrderRepo) GetMany() ([]orders.Order, error)

func (*PostgresOrderRepo) GetOne

func (por *PostgresOrderRepo) GetOne(id string) (*orders.Order, error)

func (*PostgresOrderRepo) Save

func (por *PostgresOrderRepo) Save(order *orders.Order) error

type SqliteOrderRepo

type SqliteOrderRepo struct {
	// contains filtered or unexported fields
}

func NewSqliteOrderRepo

func NewSqliteOrderRepo(db *sql.DB, logger *zap.SugaredLogger) *SqliteOrderRepo

func (*SqliteOrderRepo) GetMany

func (repo *SqliteOrderRepo) GetMany() ([]orders.Order, error)

func (*SqliteOrderRepo) GetOne

func (repo *SqliteOrderRepo) GetOne(id string) (*orders.Order, error)

func (*SqliteOrderRepo) Save

func (repo *SqliteOrderRepo) Save(order *orders.Order) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL