This repository has been archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.go
108 lines (89 loc) · 2.51 KB
/
model.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package domo
import (
"errors"
"fmt"
"time"
)
type DataSet struct {
ID string `json:"id,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Schema *Schema `json:"schema,omitempty"`
Rows int `json:"rows,omitempty"`
Columns int `json:"columns,omitempty"`
Owner *User `json:"owner,omitempty"`
}
func (d DataSet) validateRequest() error {
if d.Name == "" {
return errors.New("missing name")
}
if d.Schema == nil {
return errors.New("missing schema")
}
if len(d.Schema.Columns) == 0 {
return errors.New("len(schema.Columns) is zero")
}
return nil
}
type UpdateMethod string
const (
UpdateMethodAppend UpdateMethod = "APPEND"
UpdateMethodReplace UpdateMethod = "REPLACE"
)
type Schema struct {
Columns Columns `json:"columns,omitempty"`
}
type Column struct {
Type ColumnType `json:"type,omitempty"`
Name string `json:"name,omitempty"`
}
type ColumnType string
const (
ColumnString ColumnType = "STRING"
ColumnDecimal ColumnType = "DECIMAL"
ColumnLong ColumnType = "LONG"
ColumnDouble ColumnType = "DOUBLE"
ColumnDate ColumnType = "DATE"
ColumnDateTime ColumnType = "DATETIME"
)
type Columns []Column
type User struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
type Stream struct {
ID int `json:"id,omitempty"`
DataSet *DataSet `json:"dataSet,omitempty"`
UpdateMethod UpdateMethod `json:"updateMethod,omitempty"`
}
func (r Stream) validateRequest() error {
if r.DataSet == nil {
return errors.New("missing DataSet")
}
if r.DataSet.ID != "" {
return fmt.Errorf("DataSet.ID = %s, expected empty", r.DataSet.ID)
}
if err := r.DataSet.validateRequest(); err != nil {
return fmt.Errorf("invalid DataSet - %w", err)
}
if r.UpdateMethod == "" {
return errors.New("missing UpdateMethod")
}
return nil
}
type StreamExecution struct {
ID int `json:"id,omitempty"`
StartedAt time.Time `json:"startedAt,omitempty"`
CurrentState StreamExecutionState `json:"currentState,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
ModifiedAt time.Time `json:"modifiedAt,omitempty"`
}
type StreamExecutionState string
const (
StreamExecutionActive StreamExecutionState = "ACTIVE"
)
func Time(ts time.Time) string {
return ts.Format(time.RFC3339)
}