-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
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 theWatch()implementation relies on internals of the specificclient(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
Labels
No labels