Replies: 5 comments
-
I'm not totally convinced that this is a common-enough pattern to warrant inclusion in Go kit. But I'm subject to my own biases. Would other users care to chime in? |
Beta Was this translation helpful? Give feedback.
-
Also, passing dependencies via |
Beta Was this translation helpful? Give feedback.
-
@yurishkuro Hrm... If I'm interpreting what you mean by "transaction-scoped", I believe that's what this is using it for... In the context of a web request (ACK that this might be used in non-HTTP usages), I believe the process would be pull whatever you need off the incoming request to identify the requesting user, build the request-scoped datum (in the LD example, it'd be one of their User structs), and put that in the Context... The non-request-scoped stuff is injected much earlier at construction time (feature flag key, error handling, client, etc.) of the feature flag (e.g. Booler), and you hand the Booler around as a dependency to the structs that need to consume them and operate conditionally. |
Beta Was this translation helpful? Give feedback.
-
perhaps I am not understanding what you're proposing. If the application's handler extracts app-specific information from the request (like that User struct), it can certainly store it in the context, but that does not require any additional framework. Neither the representation of that data nor its extraction from the request can be generalized since it's specific to the application. So what would these |
Beta Was this translation helpful? Give feedback.
-
The intention is for the interfaces to express "If you need vendor-specific information to calculate the flag results, the established mechanism to send that information is via the Context." In the Maybe a concrete(-ish) example will help?
|
Beta Was this translation helpful? Give feedback.
-
Much like the
metrics
package, I believe Feature Flags (/Toggles/etc...) should be handled similarly:Would the project be open to receiving a contribution of a
flags
package, contained in it a couple of helper and concrete implementation packages:default
(always returns the same value);random
(randomly delivers results from a discrete list of options);launchdarkly
(because this the service I use in my own projects).The set of interfaces would probably be a bit wider than the 3 main interfaces in
metrics
, maybe something akin to this:OptBool(context.Context) bool
OptString(context.Context) string
OptJSON(context.Context) json.RawMessage
OptInt64(context.Context) int64
OptFloat64(context.Context) float64
This would standardize on using
context.Context
to hold any targeting information. (E.g. LaunchDarkly uses their ownUser
struct for deciding on which option to return.)Beta Was this translation helpful? Give feedback.
All reactions