-
Notifications
You must be signed in to change notification settings - Fork 1
/
host_group.go
31 lines (26 loc) · 1000 Bytes
/
host_group.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
package hostgroup
import (
"github.com/ScoreTrak/ScoreTrak/pkg/host"
"github.com/gofrs/uuid"
"gorm.io/gorm"
)
// HostGroup model represents a set of hosts that have a common purpose, but are in different teams. For instance team 1 web, and team 2 web would bellong to a host group Web
type HostGroup struct {
ID uuid.UUID `json:"id,omitempty" gorm:"type:uuid;primary_key;"`
Name string `json:"name" gorm:"not null; unique"`
// Hide is responsible for hiding the Host Group on scoring table
Hide *bool `json:"pause,omitempty" gorm:"not null;default:false"`
// Pause is responsible for pausing the Host Group on scoring table
Pause *bool `json:"hide,omitempty" gorm:"not null;default:false"`
Hosts []*host.Host `json:"hosts,omitempty" gorm:"foreignkey:HostGroupID; constraint:OnUpdate:RESTRICT,OnDelete:RESTRICT"`
}
func (h *HostGroup) BeforeCreate(_ *gorm.DB) (err error) {
if h.ID == uuid.Nil {
u, err := uuid.NewV4()
if err != nil {
return err
}
h.ID = u
}
return nil
}