/
system.go
47 lines (37 loc) · 991 Bytes
/
system.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
package system
import (
"database/sql"
"fmt"
"time"
"gorm.io/gorm"
)
type Settings struct {
gorm.Model
MaintenanceMode bool `gorm:"column:maintenance_mode;default:false"`
PausedSince sql.NullTime `gorm:"column:paused_since"`
}
func (s *Settings) String() string {
return fmt.Sprintf("MaintenanceMode: %t", s.MaintenanceMode)
}
func (Settings) TableName() string {
return "system_settings"
}
// Convert to JSON version
func (s *Settings) ToJSON() SettingsJSON {
return SettingsJSON{
MaintenanceMode: s.MaintenanceMode,
}
}
func (s *Settings) IsMaintenanceMode() bool {
return s.MaintenanceMode
}
func (s *Settings) IsPaused(pauseDuration time.Duration) bool {
return s.PausedSince.Valid && s.PausedSince.Time.After(time.Now().Add(-pauseDuration))
}
// Update fields according to JSON version
func (s *Settings) FromJSON(j SettingsJSON) {
s.MaintenanceMode = j.MaintenanceMode
}
type SettingsJSON struct {
MaintenanceMode bool `json:"maintenanceMode"`
}