Skip to content

[v1][breaking] Rethink Setter.AddDataToContext signature #87

@robbyt

Description

@robbyt

Summary

platform/data/provider.go:15-31:

type Setter interface {
    AddDataToContext(ctx context.Context, data ...map[string]any) (context.Context, error)
}

Two friction points showing up at every call site:

  1. The variadic ...map[string]any is rarely used variadically — most call sites pass exactly one map. The variadic form forces processValue to special-case *http.Request unwrapping (platform/data/contextProvider.go:101-126), which suggests ...any would be more honest if we want to keep the variadic at all.

  2. The (ctx, error) return is awkward when the call has no real error path. ContextProvider only errors when its key is empty (a programming error). Callers always have to do the ctx, err := ...; if err != nil { ... } dance even when there's nothing to recover from.

Proposal

Pick one of:

  • Drop the variadic and document one map per call.
  • Change the variadic to ...any and document the support matrix (map[string]any, *http.Request, structs, etc.).
  • Provide a no-error helper for the common case alongside the interface (e.g. MustAddData(ctx, data) or WithRuntimeData(ctx, data) context.Context).

Files

  • platform/data/provider.go:15-31
  • platform/data/contextProvider.go:53-93
  • platform/data/staticProvider.go:40-45
  • platform/data/compositeProvider.go:89-150

This is a breaking-change candidate for v1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions