feat(octetcounting,nontransparent): restore backward compatibility while keeping WithMachineOptions
#36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR restores backward compatibility with v4.2.0 by re-adding support for the
syslog.WithBestEffort()API, while preserving all improvements introduced in PR #23 (syslog.WithMachineOptions()).Problem
PR #23 introduced breaking changes by:
BestEfforterfrom theParserinterfacesyslog.WithBestEffort()generic optionsyslog.WithMachineOptions(rfc5424.WithBestEffort())While this is a useful pattern in some scenarios, it would have forced a major version bump to v5.0.0 and broken existing user code.
Solution
Support both APIs simultaneously by:
BestEfforterto theParserinterfacesyslog.WithBestEffort()generic optionbestEffortflag to aMachineOptioninternallyHow It Works
The old
bestEffort boolflag is maintained for backward compatibility. When set via the old API, it's automatically converted to the appropriateMachineOptionduring parser construction:This means both APIs produce identical behavior:
Old API (backward compatible):
New API (from PR #23):
Mixed (also works):
Benefits
WithMachineOptionsAPI fully functionalChanges
syslog.go- Re-addedBestEffortertoParserinterfaceoptions.go- RestoredWithBestEffort()generic optionnontransparent/parser.go.rl- Added backward compatibility logicnontransparent/parser.go- Regenerated from ragel sourceoctetcounting/parser.go- Added backward compatibility logic*_test.go- Added comprehensive tests for both APIsTesting
All existing tests pass, plus new tests verify: