-
Notifications
You must be signed in to change notification settings - Fork 6
docs: correct Nil processor description, errors.As guidance, and file structure #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,11 +34,11 @@ GoBatch is a Go library for batch data processing. It provides infrastructure fo | |
| - Include practical examples in documentation | ||
|
|
||
| ## File Structure | ||
| - `/batch`: Core batch processing functionality, includes the main Batch type, configuration, errors, and helper functions | ||
| - `/processor`: Different processors for data manipulation (Transform, Filter, Channel, Error, Nil) | ||
| - `/source`: Data sources for batch processing (Channel, Error, Nil) | ||
| - `/doc.go`: Package-level documentation | ||
| - `/example_test.go`: Top-level usage examples | ||
| - `/batch`: Core batch processing package. Includes `batch.go` (the main `Batch` type and pipeline), `config.go` (Config interface, ConstantConfig, DynamicConfig, BufferConfig), `errors.go` (SourceError, ProcessorError), `constants.go`, `helpers.go` (IgnoreErrors, CollectErrors, RunBatchAndWait, ExecuteBatches), and `doc.go`. Accompanied by unit tests (`*_test.go`) and several runnable `example_*_test.go` files. | ||
| - `/processor`: Processor implementations — `transform.go`, `filter.go`, `channel.go`, `error.go`, `nil.go` — plus `doc.go` and tests. | ||
| - `/source`: Source implementations — `channel.go`, `error.go`, `nil.go` — plus `doc.go` and tests. | ||
| - `/doc.go`: Root package-level documentation. | ||
| - `/example_test.go`: Top-level usage examples. | ||
|
|
||
| ## Key Concepts | ||
| - **Batch**: Main type that orchestrates the batch processing pipeline | ||
|
|
@@ -57,7 +57,7 @@ GoBatch is a Go library for batch data processing. It provides infrastructure fo | |
| - **Filter**: Filters items based on a predicate function | ||
| - **Channel**: Writes item data to an output channel | ||
| - **Error**: Simulates processor errors (for testing) | ||
| - **Nil**: Passes items through unchanged (for benchmarking) | ||
| - **Nil**: Sleeps for a configurable `Duration` without modifying item data (can mark items cancelled via `MarkCancelled`); useful for simulating slow processing and testing timing behavior | ||
|
|
||
| ### Sources | ||
| - **Channel**: Uses Go channels as data sources | ||
|
|
@@ -75,4 +75,4 @@ GoBatch is a Go library for batch data processing. It provides infrastructure fo | |
| - Processors should respect context cancellation | ||
| - Items with errors are tracked individually through the Error field | ||
| - Batch processing continues despite individual item errors | ||
| - Use `errors.As` to check error types (SourceError, ProcessorError) | ||
| - Use `errors.As` to check error types (SourceError, ProcessorError). The engine wraps errors as pointers (`&SourceError{...}`, `&ProcessorError{...}`), so `errors.As` must target the pointer type — e.g. `var se *batch.SourceError; errors.As(err, &se)` (equivalently `errors.As(err, new(*batch.SourceError))`). A value-target such as `var se batch.SourceError; errors.As(err, &se)` will not match. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parenthetical In Go, the standard and idiomatic way to use var se *batch.SourceError
errors.As(err, &se)Using Additionally, the phrase "The engine wraps errors as pointers" could be more precisely stated as "The engine returns errors as pointers" or "The engine instantiates errors as pointers", since "wrapping" in Go errors typically refers to the Consider simplifying and refining this sentence: - Use `errors.As` to check error types (SourceError, ProcessorError). The engine returns errors as pointers (`*SourceError`, `*ProcessorError`), so `errors.As` must target the pointer type — e.g., `var se *batch.SourceError; errors.As(err, &se)`. A value-target such as `var se batch.SourceError; errors.As(err, &se)` will not match. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parenthetical
(equivalently errors.As(err, new(*batch.SourceError)))is technically correct but highly non-idiomatic in Go.In Go, the standard and idiomatic way to use
errors.Aswith a pointer type is:Using
new(*batch.SourceError)is rarely seen and can confuse readers because it returns a double pointer (**batch.SourceError), requiring extra dereferencing to access the error fields.Additionally, the phrase "The engine wraps errors as pointers" could be more precisely stated as "The engine returns errors as pointers" or "The engine instantiates errors as pointers", since "wrapping" in Go errors typically refers to the
Unwrapchain rather than pointer vs. value types.Consider simplifying and refining this sentence: