forked from algolia/algoliasearch-client-go
/
types_batch.go
41 lines (33 loc) · 931 Bytes
/
types_batch.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
package algoliasearch
type BatchOperation struct {
Action string `json:"action"`
Body interface{} `json:"body,omitempty"`
}
type BatchOperationIndexed struct {
BatchOperation
IndexName string `json:"indexName"`
}
type BatchRes struct {
ObjectIDs []string `json:"objectIDs"`
TaskID int `json:"taskID"`
}
type MultipleBatchRes struct {
ObjectIDs []string `json:"objectIDs"`
TaskID map[string]int `json:"taskID"`
}
func newBatchOperations(objects []Object, action string) (operations []BatchOperation, err error) {
operations = make([]BatchOperation, len(objects))
for i, o := range objects {
// In the case of something else than `addObject` and `clear`
// operations, the `objectID` field is required.
if action != "addObject" && action != "clear" {
_, err = o.ObjectID()
if err != nil {
return
}
}
operations[i].Action = action
operations[i].Body = o
}
return
}