-
Notifications
You must be signed in to change notification settings - Fork 53
/
result.go
59 lines (48 loc) · 1.02 KB
/
result.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
package models
import (
"github.com/crawlab-team/crawlab-core/interfaces"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Result bson.M
func (r *Result) GetId() (id primitive.ObjectID) {
res, ok := r.Value()["_id"]
if ok {
id, ok = res.(primitive.ObjectID)
if ok {
return id
}
}
return id
}
func (r *Result) SetId(id primitive.ObjectID) {
(*r)["_id"] = id
}
func (r *Result) Value() map[string]interface{} {
return *r
}
func (r *Result) SetValue(key string, value interface{}) {
(*r)[key] = value
}
func (r *Result) GetValue(key string) (value interface{}) {
return (*r)[key]
}
func (r *Result) GetTaskId() (id primitive.ObjectID) {
res := r.GetValue("_tid")
if res == nil {
return id
}
id, _ = res.(primitive.ObjectID)
return id
}
func (r *Result) SetTaskId(id primitive.ObjectID) {
r.SetValue("_tid", id)
}
type ResultList []Result
func (l *ResultList) GetModels() (res []interfaces.Model) {
for i := range *l {
d := (*l)[i]
res = append(res, &d)
}
return res
}