|
1 | 1 | package openai |
2 | 2 |
|
3 | | -// Option specifies instrumentation configuration options. |
| 3 | +// Option is an interface that specifies instrumentation configuration options. |
4 | 4 | type Option interface { |
5 | 5 | apply(*config) |
6 | 6 | } |
7 | 7 |
|
8 | | -var _ Option = (*optionFunc)(nil) |
9 | | - |
| 8 | +// optionFunc is a type of function that can be used to implement the Option interface. |
| 9 | +// It takes a pointer to a config struct and modifies it. |
10 | 10 | type optionFunc func(*config) |
11 | 11 |
|
| 12 | +// Ensure that optionFunc satisfies the Option interface. |
| 13 | +var _ Option = (*optionFunc)(nil) |
| 14 | + |
| 15 | +// The apply method of optionFunc type is implemented here to modify the config struct based on the function passed. |
12 | 16 | func (o optionFunc) apply(c *config) { |
13 | 17 | o(c) |
14 | 18 | } |
15 | 19 |
|
| 20 | +// WithToken is a function that returns an Option, which sets the token field of the config struct. |
16 | 21 | func WithToken(val string) Option { |
17 | 22 | return optionFunc(func(c *config) { |
18 | 23 | c.token = val |
19 | 24 | }) |
20 | 25 | } |
21 | 26 |
|
| 27 | +// WithOrgID is a function that returns an Option, which sets the orgID field of the config struct. |
22 | 28 | func WithOrgID(val string) Option { |
23 | 29 | return optionFunc(func(c *config) { |
24 | 30 | c.orgID = val |
25 | 31 | }) |
26 | 32 | } |
27 | 33 |
|
| 34 | +// WithModel is a function that returns an Option, which sets the model field of the config struct. |
28 | 35 | func WithModel(val string) Option { |
29 | 36 | return optionFunc(func(c *config) { |
30 | 37 | c.model = val |
31 | 38 | }) |
32 | 39 | } |
33 | 40 |
|
| 41 | +// WithProxyURL is a function that returns an Option, which sets the proxyURL field of the config struct. |
34 | 42 | func WithProxyURL(val string) Option { |
35 | 43 | return optionFunc(func(c *config) { |
36 | 44 | c.proxyURL = val |
37 | 45 | }) |
38 | 46 | } |
39 | 47 |
|
| 48 | +// config is a struct that stores configuration options for the instrumentation. |
40 | 49 | type config struct { |
41 | 50 | token string |
42 | 51 | orgID string |
|
0 commit comments