-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_test.go
77 lines (63 loc) · 1.79 KB
/
setup_test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package bongoz
import (
"github.com/DailyFeats/dpl/models/traits"
"github.com/maxwellhealth/bongo"
"github.com/maxwellhealth/mgo/bson"
"net/http"
"time"
// "net/url"
"errors"
"reflect"
)
func errorMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not Authorized", http.StatusUnauthorized)
// h.ServeHTTP(w, r)
})
}
type singleResponse struct {
Data map[string]interface{}
}
type Page struct {
bongo.DocumentBase `bson:",inline"`
Content string
IntValue int `bson:"intValue"`
DateValue time.Time `bson:"dateValue"`
ArrValue []string `bson:"arrValue"`
IdArr []bson.ObjectId `bson:"idArr"`
IdValue bson.ObjectId `json:",omitempty" bson:"idValue,omitempty"`
RandomMap map[string]interface{} `bson:"randomMap"`
}
func Factory() bongo.Document {
return &Page{}
}
type HistoricalPage struct {
Page `bson:",inline"`
traits.Historical `bson:",inline"`
OtherVal string
diffTracker *bongo.DiffTracker
}
func (f *HistoricalPage) GetDiffTracker() *bongo.DiffTracker {
v := reflect.ValueOf(f.diffTracker)
if !v.IsValid() || v.IsNil() {
f.diffTracker = bongo.NewDiffTracker(f)
}
return f.diffTracker
}
func HistoricalFactory() bongo.Document {
return &HistoricalPage{}
}
type validatedModel struct {
bongo.DocumentBase `bson:",inline"`
Content string `json:"content"`
}
func ValidFactory() bongo.Document {
return &validatedModel{}
}
func (v *validatedModel) Validate(collection *bongo.Collection) []error {
ret := []error{}
if !bongo.ValidateRequired(v.Content) {
ret = append(ret, errors.New("Content is required"))
}
return ret
}