/
models.go
44 lines (38 loc) · 975 Bytes
/
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
package service
import (
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)
// createSchema creates database schema for the models
func createSchema(db *pg.DB) error {
tables := []interface{}{
(*LedDeviceModel)(nil),
(*HealthzModel)(nil),
}
for _, model := range tables {
err := db.Model(model).CreateTable(&orm.CreateTableOptions{
IfNotExists: true,
})
if err != nil {
return err
}
}
return nil
}
type HealthzModel struct {
IsHealthy bool `json:"is_healthy"`
ErrorMessage string `json:"error_message"`
}
type LedDeviceModel struct {
ID string `json:"id"`
Name string `json:"name"`
//NumLeds int `json:"num_leds"`
//SupportedModes []string `json:"supported_modes"`
//CurrentMode string `json:"current_mode"`
//IPAddress string `json:"ip_address"`
//Data interface{} `json:"data"`
}
type JsonError struct {
Code int `json:"code"`
ErrorMessage string `json:"error_message"`
}