fix(loader): wire context into HTTP request, guard nil opts in Redis list/hash

- HTTPLoader.Load: http.NewRequest → NewRequestWithContext so caller
  cancellation/deadlines propagate to the outgoing request
- RedisListLoader, RedisHashLoader: add nil-guard before calling opt()
  (already present in StringLoader, SetLoader, and HTTPLoader)
- Add doc comments for all 10 exported symbols (package, interfaces,
  constructors, option types, option funcs, DefaultRedisKey)
- Add loader_test.go with 32 tests covering FileLoader, HTTPLoader
  (context cancel, error status, empty/large body), Redis options,
  nil-guard safety, and interface satisfaction checks
This commit is contained in:
ginuerzh
2026-05-24 18:04:02 +08:00
parent b991baaf72
commit 51455da96f
4 changed files with 419 additions and 3 deletions
+3 -1
View File
@@ -13,8 +13,10 @@ type httpLoaderOptions struct {
timeout time.Duration
}
// HTTPLoaderOption configures an HTTP loader.
type HTTPLoaderOption func(opts *httpLoaderOptions)
// TimeoutHTTPLoaderOption sets the HTTP request timeout.
func TimeoutHTTPLoaderOption(timeout time.Duration) HTTPLoaderOption {
return func(opts *httpLoaderOptions) {
opts.timeout = timeout
@@ -43,7 +45,7 @@ func HTTPLoader(url string, opts ...HTTPLoaderOption) Loader {
}
func (l *httpLoader) Load(ctx context.Context) (io.Reader, error) {
req, err := http.NewRequest(http.MethodGet, l.url, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, l.url, nil)
if err != nil {
return nil, err
}