mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-06 15:46:37 +08:00
autoresearch iter 7: share body field extraction across push channels
email, telegram and lark each re-implemented the title/content/level lookup with only their markup differing, and each carried a dead content := "" initialization that every branch overwrote. Three small helpers in template.go now own that logic.
This commit is contained in:
@@ -76,3 +76,32 @@ func formatValue(v any) string {
|
||||
return fmt.Sprintf("%v", v)
|
||||
}
|
||||
}
|
||||
|
||||
// bodyTitle returns the notification title, falling back to the default.
|
||||
func bodyTitle(body map[string]any) string {
|
||||
if t, ok := body["title"].(string); ok && t != "" {
|
||||
return t
|
||||
}
|
||||
return defaultTitle
|
||||
}
|
||||
|
||||
// bodyContent returns the notification body, rendering every entry with format
|
||||
// (a "%s … %v" pair) and joining them with sep when no content field is given.
|
||||
func bodyContent(body map[string]any, format, sep string) string {
|
||||
if c, ok := body["content"].(string); ok && c != "" {
|
||||
return c
|
||||
}
|
||||
parts := make([]string, 0, len(body))
|
||||
for k, v := range body {
|
||||
parts = append(parts, fmt.Sprintf(format, k, v))
|
||||
}
|
||||
return strings.Join(parts, sep)
|
||||
}
|
||||
|
||||
// bodyLevel returns the upper-cased notification level, falling back to INFO.
|
||||
func bodyLevel(body map[string]any) string {
|
||||
if l, ok := body["level"].(string); ok && l != "" {
|
||||
return strings.ToUpper(l)
|
||||
}
|
||||
return levelInfo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user