Add comments to JSON Lines parser for improved documentation

This commit is contained in:
2026-03-14 11:41:24 +05:00
parent b47597310c
commit c1e0d071a6

View File

@@ -7,12 +7,14 @@ import (
"strings" "strings"
) )
// jsonLinesExtract defines the function signature for extracting IP addresses from a JSON Lines item.
type jsonLinesExtract func(item json.RawMessage) (string, error) type jsonLinesExtract func(item json.RawMessage) (string, error)
type jsonLinesParser struct { type jsonLinesParser struct {
extract jsonLinesExtract extract jsonLinesExtract
} }
// NewJsonLines creates a new JSON Lines parser.
func NewJsonLines(extract jsonLinesExtract) (Parser, error) { func NewJsonLines(extract jsonLinesExtract) (Parser, error) {
if extract == nil { if extract == nil {
return nil, fmt.Errorf("json lines extract is nil") return nil, fmt.Errorf("json lines extract is nil")
@@ -23,6 +25,8 @@ func NewJsonLines(extract jsonLinesExtract) (Parser, error) {
}, nil }, nil
} }
// Parse parses the JSON Lines data from the given reader.
// It returns a slice of IP addresses and any errors that occurred during the process.
func (p *jsonLinesParser) Parse(body io.Reader, validator IPValidator, limit uint) (IPs, error) { func (p *jsonLinesParser) Parse(body io.Reader, validator IPValidator, limit uint) (IPs, error) {
decoder := json.NewDecoder(body) decoder := json.NewDecoder(body)
ips := make(IPs, 0) ips := make(IPs, 0)