forked from algolia/algoliasearch-client-go
/
types_object.go
46 lines (37 loc) · 886 Bytes
/
types_object.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
package algoliasearch
import (
"encoding/json"
"fmt"
)
type CreateObjectRes struct {
CreatedAt string `json:"createdAt"`
ObjectID string `json:"objectID"`
TaskID int `json:"taskID"`
}
type UpdateObjectRes struct {
ObjectID string `json:"objectID"`
TaskID int `json:"taskID"`
UpdatedAt string `json:"updatedAt"`
}
type objects struct {
Results []Object `json:"results"`
}
type Object Map
func (o Object) ObjectID() (objectID string, err error) {
i, ok := o["objectID"]
if !ok {
err = fmt.Errorf("Cannot extract `objectID` field from Object `%s`", o)
return
}
if objectID, ok = i.(string); !ok {
err = fmt.Errorf("Cannot cast `objectID` field to string type from Object `%s`", o)
}
return
}
func (o Object) String() string {
jsonContent, err := json.Marshal(&o)
if err == nil {
return string(jsonContent)
}
return fmt.Sprintf("%#v", o)
}