-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tonybka/feature/tonybka/init-code
Init code base
- Loading branch information
Showing
7 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package entity | ||
|
||
import "github.com/tonybka/go-base-ddd/event" | ||
|
||
type BaseAggregateRoot struct { | ||
BaseEntity | ||
} | ||
|
||
func (aggregate *BaseAggregateRoot) AddEvent(event event.IBaseDomainEvent) { | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package entity | ||
|
||
import "github.com/google/uuid" | ||
|
||
type BaseEntity struct { | ||
ID uuid.UUID | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package event | ||
|
||
type IBaseDomainEvent struct { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/tonybka/go-base-ddd | ||
|
||
go 1.18 | ||
|
||
require github.com/google/uuid v1.3.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= | ||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package gorm | ||
|
||
import ( | ||
"database/sql/driver" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
type CustomTypeUUIDv1 uuid.UUID | ||
|
||
// NewCustomTypeUUIDv1FromString -> parse string to CustomTypeUUIDv1 | ||
func NewCustomTypeUUIDv1FromString(s string) (CustomTypeUUIDv1, error) { | ||
id, err := uuid.Parse(s) | ||
return CustomTypeUUIDv1(id), err | ||
} | ||
|
||
//String -> String Representation of Binary16 | ||
func (my CustomTypeUUIDv1) String() string { | ||
return uuid.UUID(my).String() | ||
} | ||
|
||
//GormDataType -> sets type to binary(16) | ||
func (my CustomTypeUUIDv1) GormDataType() string { | ||
return "binary(16)" | ||
} | ||
|
||
func (my CustomTypeUUIDv1) MarshalJSON() ([]byte, error) { | ||
s := uuid.UUID(my) | ||
str := "\"" + s.String() + "\"" | ||
return []byte(str), nil | ||
} | ||
|
||
func (my *CustomTypeUUIDv1) UnmarshalJSON(by []byte) error { | ||
s, err := uuid.ParseBytes(by) | ||
*my = CustomTypeUUIDv1(s) | ||
return err | ||
} | ||
|
||
// Scan --> tells GORM how to receive from the database | ||
func (my *CustomTypeUUIDv1) Scan(value interface{}) error { | ||
|
||
bytes, _ := value.([]byte) | ||
parseByte, err := uuid.FromBytes(bytes) | ||
*my = CustomTypeUUIDv1(parseByte) | ||
return err | ||
} | ||
|
||
// Value -> tells GORM how to save into the database | ||
func (my CustomTypeUUIDv1) Value() (driver.Value, error) { | ||
return uuid.UUID(my).MarshalBinary() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package valueobject | ||
|
||
import "fmt" | ||
|
||
type IStringValueObject interface { | ||
fmt.Stringer | ||
Equals(value IStringValueObject) bool | ||
} |