1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

TRANSIP: Improve diff2 implementation (#2228)

Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
Vincent Hagen
2023-03-26 18:51:45 +02:00
committed by GitHub
parent c34a1a6ed1
commit 9ffec690f5
2 changed files with 151 additions and 54 deletions

View File

@@ -56,28 +56,13 @@ General instructions:
for _, change := range changes {
switch change.Type {
case diff2.REPORT:
corr = &models.Correction{Msg: change.MsgsJoined}
corr = change.CreateMessage()
case diff2.CREATE:
corr = &models.Correction{
Msg: change.MsgsJoined,
F: func() error {
return c.createRecord(FILL_IN)
},
}
corr = change.CreateCorrection(func() error { return c.createRecord(FILL_IN) })
case diff2.CHANGE:
corr = &models.Correction{
Msg: change.MsgsJoined,
F: func() error {
return c.modifyRecord(FILL_IN)
},
}
corr = change.CreateCorrection(func() error { return c.modifyRecord(FILL_IN) })
case diff2.DELETE:
corr = &models.Correction{
Msg: change.MsgsJoined,
F: func() error {
return c.deleteRecord(FILL_IN)
},
}
corr = change.CreateCorrection(func() error { return c.deleteRecord(FILL_IN) })
default:
panic("unhandled change.TYPE %s", change.Type)
}
@@ -90,6 +75,33 @@ General instructions:
*/
// CreateCorrection creates a new Correction based on the given
// function and prefills it with the Msg of the current Change
func (c *Change) CreateCorrection(correctionFunction func() error) *models.Correction {
return &models.Correction{
F: correctionFunction,
Msg: c.MsgsJoined,
}
}
// CreateMessage creates a new correction with only the message.
// Used for diff2.Report corrections
func (c *Change) CreateMessage() *models.Correction {
return &models.Correction{
Msg: c.MsgsJoined,
}
}
// CreateCorrectionWithMessage creates a new Correction based on the
// given function and prefixes given function with the Msg of the
// current change
func (c *Change) CreateCorrectionWithMessage(msg string, correctionFunction func() error) *models.Correction {
return &models.Correction{
F: correctionFunction,
Msg: fmt.Sprintf("%s: %s", msg, c.MsgsJoined),
}
}
// ByRecordSet takes two lists of records (existing and desired) and
// returns instructions for turning existing into desired.
//