Skip to content

Commit

Permalink
refactor: text handling in handler.go
Browse files Browse the repository at this point in the history
  • Loading branch information
iret-kawashima committed Dec 5, 2023
1 parent ca3a04f commit b7ec4c8
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ func JSONLineHandler(labels []string, values []string, index int, hasIndex bool)
builder.WriteString("\"")
builder.WriteString(labels[i])
builder.WriteString("\":")
b, err := json.Marshal(value)
if err != nil {
return "", fmt.Errorf("cannot marshal matched string \"%s\": %w", value, err)
}
builder.Write(b)
builder.WriteString(strconv.Quote(value))
}
}
builder.WriteString("}")
Expand Down Expand Up @@ -89,12 +85,8 @@ func KeyValuePairLineHandler(labels []string, values []string, index int, hasInd
builder.WriteString(" ")
}
builder.WriteString(labels[i])
builder.WriteString(`=`)
b, err := json.Marshal(value)
if err != nil {
return "", fmt.Errorf("cannot marshal matched string \"%s\": %w", value, err)
}
builder.Write(b)
builder.WriteString("=")
builder.WriteString(strconv.Quote(value))
}
}
return builder.String(), nil
Expand All @@ -113,13 +105,7 @@ func KeyValuePairMetadataHandler(m *Metadata) (string, error) {
builder.WriteString(" skipped=")
builder.WriteString(strconv.Itoa(m.Skipped))
builder.WriteString(" source=")
if m.Source == "" {
builder.WriteString("\"\"")
} else {
builder.WriteString("\"")
builder.WriteString(m.Source)
builder.WriteString("\"")
}
builder.WriteString(strconv.Quote(m.Source))
builder.WriteString(" errors=")
e, err := json.Marshal(m.Errors)
if err != nil {
Expand Down

0 comments on commit b7ec4c8

Please sign in to comment.