-
Notifications
You must be signed in to change notification settings - Fork 903
GODRIVER-3037 Support internal-only options. #2023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
API Change Report./v2/mongo/optionscompatible changesClientOptions.Custom: added ./v2/x/mongo/driver/optionscompatible changespackage added |
mongo/options/internaloptions.go
Outdated
// SetInternalClientOptions sets internal options for ClientOptions. | ||
// | ||
// Deprecated: This function is for internal use only. It may be changed or removed in any release. | ||
func SetInternalClientOptions(opts *ClientOptions, custom map[string]any) (*ClientOptions, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this function live in the experimental API? What is the pattern for future custom data? Should ClientOptions be extended with a Custom
field of type map[string]any
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider the following pattern:
type ClientOptions struct {
custom map[string]any
}
func WithCustomValue(co ClientOptions, key string, val any) ClientOptions {}
func CustomValue(co ClientOptions key string) any {}
Then in x/mongo/driver:
const someExperimentKey = "x/mongo/driver:myExperiment"
func WithSomeExperimentValue(co options.ClientOptions, on bool) options.ClientOptions {
return options.WithCustomValue(co, someExperimentKey, on)
}
func SomeExperimentValue(co options.ClientOptions) bool {
val := options.CustomValue(co, someExperimentKey)
if b, ok := val.(bool); ok {
return b
}
return false
}
The usage would look something like this:
clientOpts, _ := options.Client()
clientOpts = driver.WithSomeExperimentValue(clientOpts, true)
// ...
And we would check it internally like this:
expVal := driver.SomeExperimentValue(clientOpts)
// ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of an expressive interface, I'd prefer a map-style interface without any hint other than a user-provided option name to add obfuscation to discourage general users from using it. However, it makes sense to wrap the map[string]any
in a struct and move it to "x/mongo/driver" to emphasize it is "experimental".
I can stack another PR for GODRIVER-3429 (internal-only "AuthenticateToAnything") on top of this one to demonstrate future custom data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this solution is fine for now, we can update if needed later.
GODRIVER-3037
Summary
Support setting internal-only options with a helper function.
Background & Motivation
This proposal does not change the current interface.
The option names are not publicly exposed to the user, so it is less likely to be used without internal knowledge.
We can add a
map[string]any
namedcustom
inClientOptions
struct for future internal options, such as AuthenticateToAnything.The
Crypt
andDeployment
fields inClientOptions
will be merged into the aforementioned map in v3.