Created
May 4, 2020 13:51
-
-
Save AntonStoeckl/3af31105ab86820d1399927d789101ef to your computer and use it in GitHub Desktop.
Example for my iDDD with Go blog article series at https://medium.com/@TonyBologni
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package value | |
import ( | |
"github.com/AntonStoeckl/go-iddd/service/shared" | |
"github.com/cockroachdb/errors" | |
"github.com/google/uuid" | |
) | |
type CustomerID struct { | |
value string | |
} | |
func GenerateCustomerID() CustomerID { | |
return CustomerID{value: uuid.New().String()} | |
} | |
func BuildCustomerID(value string) (CustomerID, error) { | |
if value == "" { | |
err := errors.New("empty input for CustomerID") | |
err = shared.MarkAndWrapError(err, shared.ErrInputIsInvalid, "BuildCustomerID") | |
return CustomerID{}, err | |
} | |
id := CustomerID{value: value} | |
return id, nil | |
} | |
func RebuildCustomerID(value string) CustomerID { | |
return CustomerID{value: value} | |
} | |
func (id CustomerID) String() string { | |
return id.value | |
} | |
func (id CustomerID) Equals(other CustomerID) bool { | |
return id.String() == other.String() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment