aboutsummaryrefslogtreecommitdiffstats
path: root/entity/merge.go
diff options
context:
space:
mode:
Diffstat (limited to 'entity/merge.go')
-rw-r--r--entity/merge.go53
1 files changed, 35 insertions, 18 deletions
diff --git a/entity/merge.go b/entity/merge.go
index 3ce8edac..0661b7fc 100644
--- a/entity/merge.go
+++ b/entity/merge.go
@@ -8,14 +8,15 @@ import (
type MergeStatus int
const (
- _ MergeStatus = iota
- MergeStatusNew
- MergeStatusInvalid
- MergeStatusUpdated
- MergeStatusNothing
- MergeStatusError
+ _ MergeStatus = iota
+ MergeStatusNew // a new Entity was created locally
+ MergeStatusInvalid // the remote data is invalid
+ MergeStatusUpdated // a local Entity has been updated
+ MergeStatusNothing // no changes were made to a local Entity (already up to date)
+ MergeStatusError // a terminal error happened
)
+// MergeResult hold the result of a merge operation on an Entity.
type MergeResult struct {
// Err is set when a terminal error occur in the process
Err error
@@ -23,10 +24,10 @@ type MergeResult struct {
Id Id
Status MergeStatus
- // Only set for invalid status
+ // Only set for Invalid status
Reason string
- // Not set for invalid status
+ // Only set for New or Updated status
Entity Interface
}
@@ -41,34 +42,50 @@ func (mr MergeResult) String() string {
case MergeStatusNothing:
return "nothing to do"
case MergeStatusError:
- return fmt.Sprintf("merge error on %s: %s", mr.Id, mr.Err.Error())
+ if mr.Id != "" {
+ return fmt.Sprintf("merge error on %s: %s", mr.Id, mr.Err.Error())
+ }
+ return fmt.Sprintf("merge error: %s", mr.Err.Error())
default:
panic("unknown merge status")
}
}
-func NewMergeError(err error, id Id) MergeResult {
+func NewMergeNewStatus(id Id, entity Interface) MergeResult {
return MergeResult{
- Err: err,
Id: id,
- Status: MergeStatusError,
+ Status: MergeStatusNew,
+ Entity: entity,
}
}
-func NewMergeStatus(status MergeStatus, id Id, entity Interface) MergeResult {
+func NewMergeInvalidStatus(id Id, reason string) MergeResult {
return MergeResult{
Id: id,
- Status: status,
+ Status: MergeStatusInvalid,
+ Reason: reason,
+ }
+}
- // Entity is not set for an invalid merge result
+func NewMergeUpdatedStatus(id Id, entity Interface) MergeResult {
+ return MergeResult{
+ Id: id,
+ Status: MergeStatusUpdated,
Entity: entity,
}
}
-func NewMergeInvalidStatus(id Id, reason string) MergeResult {
+func NewMergeNothingStatus(id Id) MergeResult {
return MergeResult{
Id: id,
- Status: MergeStatusInvalid,
- Reason: reason,
+ Status: MergeStatusNothing,
+ }
+}
+
+func NewMergeError(err error, id Id) MergeResult {
+ return MergeResult{
+ Id: id,
+ Status: MergeStatusError,
+ Err: err,
}
}