Skip to content

Can't wrap existing client with WithWatch() #2967

@2uasimojo

Description

@2uasimojo

In some cases, one can wrap already-extant client.Clients to confer extra functionality. For example:

cWithFieldOwner := client.WithFieldOwner(cWithoutFieldOwner, "owner")

However, it is not possible to confer WithWatch on an existing client: one can only obtain a client.WithWatch via a constructor:

cWithWatch, err := client.NewWithWatch(cfg, opts)

The resulting client is "frozen" -- i.e. can't be subjected to decorators like WithFieldOwner -- because those wrappers return a client.Client, which can't Watch()!

It would be great to have a decorator function to allow an existing client to grow WithWatch functionality:

c, err := client.New(cfg, opts)
c = client.WithFieldOwner(c, "owner")
// ... chain other decorators ...
cWithAllTheThings, err := client.AsWithWatch(c)

Notes:

  • It would be better to call the wrapper WithWatch, but that name is already taken by the interface. Sad face.
  • I can't think of a way to get around this client being "the end of the line". It can't be further wrapped, unless the wrapper is WithWatch-specific. Sad face.
  • It would be great if you could do this to any client.Client; but as written today that would be hard because the Watch() implementation relies on internals of the specific client (lowercase) implementation in the library. Sad face.

See #2929 where I prototyped an imperfect version of the solution that suffers from all of the above issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions