Skip to content
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

feat(client): Allow user profile service and overrides to be passed in. #168

Merged
merged 4 commits into from Nov 8, 2019

Conversation

mikeproeng37
Copy link
Contributor

@mikeproeng37 mikeproeng37 commented Nov 6, 2019

Summary

  • Introduces options for User profile service and Experiment overrides store

Tests

  • Unit (pending)

Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Draft LGTM. Probably we need to make similar changes in StaticClient as what you did in Client..

}

// OptionFunc is a type to a proper func
type OptionFunc func(*OptimizelyClient)
type OptionFunc func(*OptimizelyFactory)

// Client gets client and sets some parameters
func (f OptimizelyFactory) Client(clientOptions ...OptionFunc) (*OptimizelyClient, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, unrelated to your PR: is there a good reason that this method is defined with a value receiver, instead of a pointer receiver?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah because this method does not need to make changes to the OptimizelyFactory itself so it's safer just to make it a value receiver

Comment on lines +47 to +48
overrideStore ExperimentOverrideStore
userProfileService UserProfileService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it's a little weird that these fields are just use to move values from the option functions to a place where NewCompositeExperimentService can use them. Not sure there is a better alternative though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it was weird to me but at least they are private

Comment on lines 62 to 64
if compositeService.compositeFeatureService == nil {
compositeService.compositeFeatureService = NewCompositeFeatureService(compositeService.compositeExperimentService)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just assign this instead of check for nil, since there is not yet an option func that allows passing in compositeFeatureService?

Copy link
Contributor

@pawels-optimizely pawels-optimizely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional options in go language are usually needed to dynamically initialize an object:
https://medium.com/@dreissenzahn/functional-options-in-go-35279f535c6

The exception is that our polling config manager is doing some heavy stuff during our initialization, that's why it can be a good candidate to check after the functional options. I still think that all the light default initialization has to take place before functional options like in the example above. That will eliminate a lot of if/else and make code cleaner.

@mjc1283
Copy link
Contributor

mjc1283 commented Nov 7, 2019

@pawels-optimizely It seems more complex/potentially confusing to allow "some, but not all, fields are initialized prior to calling option functions", as opposed to initializing all fields before options, or none.

@mikeproeng37 mikeproeng37 marked this pull request as ready for review November 8, 2019 00:48
@mikeproeng37 mikeproeng37 requested a review from a team as a code owner November 8, 2019 00:48
Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'm open to additional suggestions/changes from @pawels-optimizely.

@mikeproeng37 mikeproeng37 merged commit b091387 into master Nov 8, 2019
@mikeproeng37 mikeproeng37 deleted the mng/exp-options branch November 8, 2019 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants