-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.go
69 lines (58 loc) · 1.37 KB
/
models.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
package main
import (
"math/rand"
"time"
)
type Author struct {
Id int `json:"id"`
Name string `json:"name"`
Country string `json:"country"`
}
type Book struct {
Id int `json:"id"`
Isbn13 string `json:"isbn_13"`
Isbn10 string `json:"isbn_10"`
Title string `json:"title"`
CoverImage string `json:"cover_image"`
NSites int `json:"n_sites"`
ReleaseDate string `json:"release_date"`
Author *Author `json:"author"`
}
func RandomBook() *Book {
return &Book{
Id: rand.Int(),
Isbn13: RandomString(14),
Isbn10: RandomString(13),
Title: RandomString(30),
CoverImage: RandomString(30),
NSites: rand.Int(),
ReleaseDate: RandomString(20),
Author: &Author{
Id: rand.Int(),
Name: RandomString(20),
Country: RandomString(10),
},
}
}
type Stage struct {
Node int `json:"node"`
Name string `json:"name"`
T int64 `json:"t"`
}
type TimeWrapper struct {
Payload *Book `json:"payload"`
Stages []*Stage `json:"stages"`
}
func NewTimeWrapper(payload *Book) (w *TimeWrapper) {
w = &TimeWrapper{
Payload: payload,
}
w.AddStageNow("init")
return
}
func (w *TimeWrapper) AddStage(name string, t int64) {
w.Stages = append(w.Stages, &Stage{nodeId, name, t})
}
func (w *TimeWrapper) AddStageNow(name string) {
w.AddStage(name, time.Now().UnixNano())
}