-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoptions.go
60 lines (51 loc) · 1.15 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package pinecone
type options struct {
apiKey string
environment string
projectName string
indexName string
}
type CallOptions struct {
applyFunc func(o *options)
}
func applyCallOptions(callOptions []CallOptions, defaultOptions ...options) *options {
o := new(options)
if len(defaultOptions) > 0 {
*o = defaultOptions[0]
}
for _, callOption := range callOptions {
callOption.applyFunc(o)
}
return o
}
// WithAPIKey sets the API key to use for the call.
func WithAPIKey(apiKey string) CallOptions {
return CallOptions{
applyFunc: func(o *options) {
o.apiKey = apiKey
},
}
}
// WithEnvironment sets the environment to use for the call.
func WithEnvironment(environment string) CallOptions {
return CallOptions{
applyFunc: func(o *options) {
o.environment = environment
},
}
}
// WithProjectName sets the project name to use for the call.
func WithProjectName(projectName string) CallOptions {
return CallOptions{
applyFunc: func(o *options) {
o.projectName = projectName
},
}
}
func WithIndexName(indexName string) CallOptions {
return CallOptions{
applyFunc: func(o *options) {
o.indexName = indexName
},
}
}