-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactor NewClient with options pattern #481
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #481 +/- ##
==========================================
+ Coverage 97.07% 97.16% +0.08%
==========================================
Files 17 18 +1
Lines 719 741 +22
==========================================
+ Hits 698 720 +22
Misses 15 15
Partials 6 6
|
@MarkusZhang FIY We can already.
|
@vvatanabe Oh thanks for telling, but this kinda unintuitive for the users IMO |
@vvatanabe Hi, I did a refactoring on More about options pattern: https://golang.cafe/blog/golang-functional-options-pattern.html |
Hey, thank you for this PR. A similar approach was previously discussed here: #414 (comment) The problem with setters is poor discoverability. You'll need to search through all |
@sashabaranov Thanks for the reply, I think using struct is perfectly ok, but then why not expose the |
@MarkusZhang You are right, it's less intuitive, but prevents token to be accidentally leaked. |
@sashabaranov could you elaborate a bit more? As in leak to who? what issue do you envision? |
@MarkusZhang basically you can accidentally log the client struct and have auth token printed out |
@sashabaranov Ok, then. what about this:
Then we change |
Describe the change
Some organisations may have their own GPT proxy, so when using this library, they would need to specify their proxy url. In this case, seems
NewClientWithConfig
is the only function that they can use, but right now theauthToken
field inClientConfig
is not exposed, so they won't be able to pass in auth token.Describe your solution
Refactor
NewClient
to use options pattern, so that user can use it with custom configsTests
Added new unit tests.
Issue: 480