feat: message parser with json/regex/text modes
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ParsedMessage is the result of parsing an incoming notification body.
|
||||
type ParsedMessage struct {
|
||||
Event string
|
||||
Data map[string]interface{} // field name → value, passed to template
|
||||
Body string // raw body (for text mode)
|
||||
}
|
||||
|
||||
// Parser converts a raw HTTP body into a ParsedMessage.
|
||||
type Parser interface {
|
||||
Parse(body []byte) (*ParsedMessage, error)
|
||||
}
|
||||
|
||||
func NewParser(parseMode string, parsePattern string) (Parser, error) {
|
||||
switch parseMode {
|
||||
case "json":
|
||||
return &JSONParser{}, nil
|
||||
case "regex":
|
||||
if parsePattern == "" {
|
||||
return nil, fmt.Errorf("regex parse mode requires parse_pattern")
|
||||
}
|
||||
return NewRegexParser(parsePattern)
|
||||
case "text":
|
||||
return &TextParser{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown parse_mode: %s", parseMode)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user