Skip to content

Instantly share code, notes, and snippets.

@AntonStoeckl
AntonStoeckl / structure2.txt
Created May 20, 2022 11:02
Example for Blog Post "Hexagonal Architecture: Structuring a project and the influence of granularity"
game
├── application
│   ├── deckselection
│   │   ├── commands.go # all commands
│   │   ├── commands_test.go # unit tests
│   │   ├── integration_test.go # driver adapter
│   │   ├── select_deck_command_handler.go # driver port definition and implementation
│   │   ├── select_deck_command_handler_test.go # driver adapter
│   │   ├── select_deck.go # domain logic
│   │   ├── select_deck_http_handler.go # driver adapter
@AntonStoeckl
AntonStoeckl / structure1.txt
Created May 20, 2022 10:59
Example for Blog Post "Hexagonal Architecture: Structuring a project and the influence of granularity"
game
├── application
│   ├── forselectingdecks
│   │   ├── command_handler.go # driver port definition and implementation
│   │   ├── command_handler_test.go # driver adapter
│   │   ├── command.go # command
│   │   ├── commandstest.go # unit tests
│   │   ├── http_handler.go # driver adapter
│   │   ├── integration_test.go # driver adapter
│   │   ├── select_deck.go # domain logic
@AntonStoeckl
AntonStoeckl / driven_ports.go
Last active May 20, 2022 10:58
Example for Blog Post "Hexagonal Architecture: Structuring a project and the influence of granularity"
# the coarse-grained version
type ForStoringEvents interface {
CreateEventStream(streamID lib.StreamID, event lib.Event) error
AppendEventsToStream(
streamID lib.StreamID,
expectedRevision uint64,
recordedEvents ...lib.Event,
) error
ReadEventStream(streamID lib.StreamID) (lib.EventStream, error)
@AntonStoeckl
AntonStoeckl / function_types.go
Created May 20, 2022 10:57
Example for Blog Post "Hexagonal Architecture: Structuring a project and the influence of granularity"
# With function types instead of interfaces all ports are automatically fine-grained
type ForSelectingDecks func(command SelectDeckCommand) error
type ForUnselectingDecks func(command UnselectDeckCommand) error
@AntonStoeckl
AntonStoeckl / driver_ports.go
Created May 20, 2022 10:57
Example for Blog Post "Hexagonal Architecture: Structuring a project and the influence of granularity"
# the coarse-grained version
type ForSelectingDecks interface {
Select(command SelectDeckCommand) error
Unselect(command UnselectDeckCommand) error
}
# the fine-grained version
type ForSelectingDecks interface {
@AntonStoeckl
AntonStoeckl / command_handler.go
Created March 28, 2022 13:20
Example for blog post: Domain-Driven Design vs. "Functional Core, Imperative Shell"
package finishcard
import (
"ace-life/hexagon/domain"
"ace-life/hexagon/usecases"
)
type CommandHandler struct {
drawReplacementCard usecases.ForDrawingReplacementCards
loadEventStream usecases.ForLoadingEventStreams
@AntonStoeckl
AntonStoeckl / finish_card.go
Last active March 28, 2022 13:18
Example for blog post: Domain-Driven Design vs. "Functional Core, Imperative Shell"
package finishcard
import (
"ace-life/errtypes"
"ace-life/hexagon/domain"
"ace-life/hexagon/domain/player"
"ace-life/hexagon/events"
"ace-life/hexagon/usecases"
)
@AntonStoeckl
AntonStoeckl / functionsandinterfaces_test.go
Last active February 1, 2022 10:07
Example for blog post: Go bits: Magic with functions
package functionsandinterfaces_test
import (
"testing"
"github.com/matryer/is"
. "go-bits/magic-with-functions/functionsandinterfaces"
)
@AntonStoeckl
AntonStoeckl / functionsandinterfaces.go
Created February 1, 2022 10:06
Example for blog post: Go bits: Magic with functions
package functionsandinterfaces
type ForRegisteringCustomers interface {
Register(name, emailAddress string) error
}
type ForRegisteringCustomersFunc func(name, emailAddress string) error
// Register is a receiver method for the ForRegisteringCustomersFunc
// type that fullfills the ForRegisteringCustomers interface
@AntonStoeckl
AntonStoeckl / handler.go
Created February 1, 2022 10:03
Example for blog post: Go bits: Magic with functions
type Handler interface {
ServeHTTP(ResponseWriter, *Request)
}