Skip to content

Instantly share code, notes, and snippets.

@AntonStoeckl
AntonStoeckl / assertNotDeleted.go
Last active May 4, 2020 14:33
Example for my iDDD with Go blog article series at https://medium.com/@TonyBologni
package customer
import (
"github.com/AntonStoeckl/go-iddd/service/shared"
"github.com/cockroachdb/errors"
)
func assertNotDeleted(currentState currentState) error {
if currentState.isDeleted {
return errors.Mark(errors.New("customer was deleted"), shared.ErrNotFound)
@AntonStoeckl
AntonStoeckl / assertMatchingConfirmationHash.go
Created May 4, 2020 14:33
Example for my iDDD with Go blog article series at https://medium.com/@TonyBologni
package customer
import (
"github.com/AntonStoeckl/go-iddd/service/customeraccounts/application/domain/customer/value"
"github.com/AntonStoeckl/go-iddd/service/shared"
"github.com/cockroachdb/errors"
)
func assertMatchingConfirmationHash(current value.ConfirmationHash, supplied value.ConfirmationHash) error {
if !current.Equals(supplied) {
@AntonStoeckl
AntonStoeckl / AssertUniqueEmailAddresses.go
Last active May 7, 2020 11:07
Example for my iDDD with Go blog article series at https://medium.com/@TonyBologni
package customer
import (
"github.com/AntonStoeckl/go-iddd/service/customeraccounts/application/domain"
"github.com/AntonStoeckl/go-iddd/service/customeraccounts/application/domain/customer/value"
"github.com/AntonStoeckl/go-iddd/service/shared/es"
)
const (
ShouldAddUniqueEmailAddress = iota
@AntonStoeckl
AntonStoeckl / View.go
Created May 4, 2020 14:37
Example for my iDDD with Go blog article series at https://medium.com/@TonyBologni
package customer
import (
"github.com/AntonStoeckl/go-iddd/service/shared/es"
)
type View struct {
ID string
EmailAddress string
IsEmailAddressConfirmed bool
@AntonStoeckl
AntonStoeckl / buildCurrentStateFrom.go
Created January 8, 2022 19:29
Example for blog post "Live Projections ..."
package customer
import (
"github.com/AntonStoeckl/go-iddd/src/customeraccounts/hexagon/application/domain"
"github.com/AntonStoeckl/go-iddd/src/customeraccounts/hexagon/application/domain/customer/value"
"github.com/AntonStoeckl/go-iddd/src/shared/es"
)
type currentState struct {
id value.CustomerID
@AntonStoeckl
AntonStoeckl / BuildViewFrom.go
Created January 8, 2022 19:34
Example for blog post "Live Projections ..."
package customer
import (
"github.com/AntonStoeckl/go-iddd/src/customeraccounts/hexagon/application/domain"
"github.com/AntonStoeckl/go-iddd/src/shared/es"
)
type View struct {
ID string
EmailAddress string
@AntonStoeckl
AntonStoeckl / panic.go
Created January 14, 2022 19:58
Example for blog post Go bits: Interfaces and Nil Pointers
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4e4ea0]
@AntonStoeckl
AntonStoeckl / command.go
Created January 14, 2022 20:04
Example for blog post Go bits: Interfaces and Nil Pointers
package commandhandling
type Command interface {
CommandType() string
}
@AntonStoeckl
AntonStoeckl / register_customer.go
Created January 14, 2022 20:06
Example for blog post Go bits: Interfaces and Nil Pointers
package commandhandling
// RegisterCustomer implements the Command interface
type RegisterCustomer struct {
commandType string
// some useful properties
}
func NewRegisterCustomer() *RegisterCustomer {
return &RegisterCustomer{
@AntonStoeckl
AntonStoeckl / command_test.go
Last active January 14, 2022 20:10
Example for blog post Go bits: Interfaces and Nil Pointers
package commandhandling_test
import (
"testing"
"go-bits/interfaces-and-nil/commandhandling"
)
func TestNilInterface(_ *testing.T) {
var nilInterface commandhandling.Command