Skip to content

Refactor: Deduplicate gotask API definitions #20

@mpyw

Description

@mpyw

Problem

The gotask API list is defined in two separate locations with similar but slightly different metadata:

1. internal/apis.go - RegisterGotaskAPIs() (lines 71-89)

  • Purpose: Used by spawnerlabel checker for spawner label validation
  • Called from: analyzer.go:123
  • Data structure: registry.Entry with AlwaysSpawns field
  • APIs registered: DoAll, DoAllSettled, DoRace, DoAllFns, DoAllFnsSettled, DoRaceFns, Task.DoAsync, CancelableTask.DoAsync

2. internal/checkers/gotask.go - GotaskChecker.entries (lines 53-65)

  • Purpose: Used by gotask checker for context propagation validation
  • Called from: analyzer.go:196-200
  • Data structure: gotaskEntry with Variadic and IsDoAsync fields
  • APIs registered: Same list as above

Issues

  1. DRY violation: The same API set is maintained in two places
  2. Maintenance burden: Adding/removing gotask APIs requires changes in both locations
  3. Inconsistency risk: The two lists could drift apart over time

Key Differences

While both define the same API set, they have different metadata requirements:

Aspect RegisterGotaskAPIs GotaskChecker.entries
DoAsync CallbackArgIdx Not specified 0 (explicit)
Metadata fields AlwaysSpawns Variadic, IsDoAsync
Purpose Spawner label detection Context propagation checking

Proposed Solution

Create a unified gotask API registry that both checkers can consume:

  1. Define a single source of truth for gotask APIs (e.g., internal/gotask/apis.go)
  2. Provide adapter functions to convert to checker-specific formats:
    • ToRegistryEntries() → for spawnerlabel checker
    • ToGotaskEntries() → for gotask checker
  3. Update both checkers to use the unified registry

This would maintain flexibility for checker-specific metadata while eliminating duplication.

Alternative

If the metadata requirements are too divergent, document why the duplication is necessary and add validation to ensure both lists stay in sync.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions