@@ -24,7 +24,17 @@ func NewAccount() *Account {
24
24
// which belong to different Algolia applications. To perform the same operation
25
25
// on indices which belong to the same Algolia application, use Client.CopyIndex
26
26
// which is optimized for this use-case.
27
- func (a * Account ) CopyIndex (src , dst * Index , opts ... interface {}) (* wait.Group , error ) {
27
+ func (a * Account ) CopyIndex (src , dst * Index , opts ... string ) (* wait.Group , error ) {
28
+ // Validate scope option
29
+ hasScope := len (opts ) > 0
30
+ if hasScope {
31
+ for _ , scope := range opts {
32
+ if scope != "rules" && scope != "synonyms" && scope != "settings" {
33
+ return nil , fmt .Errorf ("wrong scope: should be 'rules', 'synonyms'or 'settings'" )
34
+ }
35
+ }
36
+ }
37
+
28
38
if src .GetAppID () == dst .GetAppID () {
29
39
return nil , errs .ErrSameAppID
30
40
}
@@ -36,7 +46,7 @@ func (a *Account) CopyIndex(src, dst *Index, opts ...interface{}) (*wait.Group,
36
46
g := wait .NewGroup ()
37
47
38
48
// Copy synonyms
39
- {
49
+ if ! hasScope || ( hasScope && SliceContains ( opts , "synonyms" )) {
40
50
it , err := src .BrowseSynonyms ()
41
51
if err != nil {
42
52
return nil , fmt .Errorf ("cannot browse source index synonyms: %v" , err )
@@ -66,7 +76,7 @@ func (a *Account) CopyIndex(src, dst *Index, opts ...interface{}) (*wait.Group,
66
76
}
67
77
68
78
// Copy rules
69
- {
79
+ if ! hasScope || ( hasScope && SliceContains ( opts , "rules" )) {
70
80
it , err := src .BrowseRules ()
71
81
if err != nil {
72
82
return nil , fmt .Errorf ("cannot browse source index rules: %v" , err )
@@ -95,7 +105,7 @@ func (a *Account) CopyIndex(src, dst *Index, opts ...interface{}) (*wait.Group,
95
105
}
96
106
97
107
// Copy settings
98
- {
108
+ if ! hasScope || ( hasScope && SliceContains ( opts , "settings" )) {
99
109
settings , err := src .GetSettings ()
100
110
if err != nil {
101
111
return nil , fmt .Errorf ("cannot retrieve source index settings: %v" , err )
@@ -141,7 +151,7 @@ func (a *Account) CopyIndex(src, dst *Index, opts ...interface{}) (*wait.Group,
141
151
}
142
152
143
153
// Send the last batch
144
- res , err := dst .SaveObjects (objects , opts )
154
+ res , err := dst .SaveObjects (objects )
145
155
if err != nil {
146
156
return nil , fmt .Errorf ("error while saving batch of objects: %v" , err )
147
157
}
0 commit comments