-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.go
53 lines (42 loc) · 945 Bytes
/
common.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
package models
import (
"encoding/json"
"gorm.io/gorm/clause"
)
type Severity string
const (
SeverityInfo Severity = "info"
SeverityLow Severity = "low"
SeverityMedium Severity = "medium"
SeverityHigh Severity = "high"
SeverityCritical Severity = "critical"
)
type Health string
const (
HealthHealthy Health = "healthy"
HealthUnhealthy Health = "unhealthy"
HealthUnknown Health = "unknown"
HealthWarning Health = "warning"
)
// asMap marshals the given struct into a map.
func asMap(t any, removeFields ...string) map[string]any {
m := make(map[string]any)
b, _ := json.Marshal(&t)
if err := json.Unmarshal(b, &m); err != nil {
return m
}
for _, field := range removeFields {
delete(m, field)
}
return m
}
type DBTable interface {
PK() string
TableName() string
}
// TODO: Find a better way to handle this
type ExtendedDBTable interface {
DBTable
Value() any
PKCols() []clause.Column
}