forked from raystack/siren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
silence.go
67 lines (56 loc) · 1.7 KB
/
silence.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
package model
import (
"database/sql"
"time"
"github.com/goto/siren/core/silence"
"github.com/goto/siren/pkg/pgc"
)
type Silence struct {
ID string `db:"id"`
NamespaceID uint64 `db:"namespace_id"`
Type string `db:"type"`
TargetID sql.NullInt64 `db:"target_id"`
TargetExpression pgc.StringAnyMap `db:"target_expression"`
Creator sql.NullString `db:"creator"`
Comment sql.NullString `db:"comment"`
CreatedAt time.Time `db:"created_at"`
DeletedAt sql.NullTime `db:"deleted_at"`
}
func (s *Silence) FromDomain(sil silence.Silence) {
s.ID = sil.ID
s.NamespaceID = sil.NamespaceID
s.Type = sil.Type
if sil.TargetID == 0 {
s.TargetID = sql.NullInt64{Valid: false}
} else {
s.TargetID = sql.NullInt64{Int64: int64(sil.TargetID), Valid: true}
}
s.TargetExpression = pgc.StringAnyMap(sil.TargetExpression)
if sil.Creator == "" {
s.Creator = sql.NullString{Valid: false}
} else {
s.Creator = sql.NullString{String: sil.Creator, Valid: true}
}
if sil.Comment == "" {
s.Comment = sql.NullString{Valid: false}
} else {
s.Comment = sql.NullString{String: sil.Comment, Valid: true}
}
s.CreatedAt = sil.CreatedAt
if sil.DeletedAt.IsZero() {
s.DeletedAt = sql.NullTime{Valid: false}
} else {
s.DeletedAt = sql.NullTime{Time: sil.DeletedAt, Valid: true}
}
}
func (s *Silence) ToDomain() *silence.Silence {
return &silence.Silence{
ID: s.ID,
NamespaceID: s.NamespaceID,
Type: s.Type,
TargetID: uint64(s.TargetID.Int64),
TargetExpression: s.TargetExpression,
CreatedAt: s.CreatedAt,
DeletedAt: s.DeletedAt.Time,
}
}