-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(updater): smart message generation (part 3 of shoutrrr suppo…
…rt) (#762)
- Loading branch information
Showing
13 changed files
with
870 additions
and
300 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
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
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
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
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,35 @@ | ||
package response | ||
|
||
type Response struct { | ||
Ok bool | ||
MonitorMessages []string | ||
NotifierMessages []string | ||
} | ||
|
||
func NewEmpty() Response { | ||
return Response{ | ||
Ok: true, | ||
MonitorMessages: nil, | ||
NotifierMessages: nil, | ||
} | ||
} | ||
|
||
func Merge(rs ...Response) Response { | ||
var ( | ||
allOk = true | ||
allMonitorMessages = map[bool][]string{true: {}, false: {}} | ||
allNotifierMessages = []string{} | ||
) | ||
|
||
for _, r := range rs { | ||
allOk = allOk && r.Ok | ||
allMonitorMessages[r.Ok] = append(allMonitorMessages[r.Ok], r.MonitorMessages...) | ||
allNotifierMessages = append(allNotifierMessages, r.NotifierMessages...) | ||
} | ||
|
||
return Response{ | ||
Ok: allOk, | ||
MonitorMessages: allMonitorMessages[allOk], | ||
NotifierMessages: allNotifierMessages, | ||
} | ||
} |
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
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,20 @@ | ||
package setter | ||
|
||
// ResponseCode encodes the minimum information to generate messages for monitors and notifiers. | ||
type ResponseCode int | ||
|
||
const ( | ||
// ResponseNoop means no changes were needed. | ||
// The records were already updated or already deleted. | ||
ResponseNoop ResponseCode = iota | ||
|
||
// ResponseUpdated means records should be updated | ||
// and we updated them, or that they should be deleted | ||
// and we deleted them. | ||
ResponseUpdated | ||
|
||
// ResponseFailed means records should be updated | ||
// but we failed to finish the updating, or that they | ||
// should be deleted and we failed to finish the deletion. | ||
ResponseFailed | ||
) |
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
Oops, something went wrong.