File size: 1,176 Bytes
1e92f2d |
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 |
package service
import (
"time"
"github.com/target/goalert/validation/validate"
)
type Service struct {
ID string
Name string
Description string
EscalationPolicyID string
MaintenanceExpiresAt time.Time
epName string
isUserFavorite bool
}
const MaxDetailsLength = 6 * 1024 // 6KiB
func (s Service) EscalationPolicyName() string {
return s.epName
}
// IsUserFavorite returns a boolean value based on if the service is a favorite of the user or not.
func (s Service) IsUserFavorite() bool {
return s.isUserFavorite
}
// Normalize will validate and 'normalize' the Service -- such as setting the minimum duration to 0.
func (s Service) Normalize() (*Service, error) {
dur := time.Until(s.MaintenanceExpiresAt)
if dur <= 0 {
dur = 0
s.MaintenanceExpiresAt = time.Time{}
}
err := validate.Many(
validate.IDName("Name", s.Name),
validate.Text("Description", s.Description, 1, MaxDetailsLength),
validate.UUID("EscalationPolicyID", s.EscalationPolicyID),
validate.Duration("MaintenanceExpiresAt", dur, 0, 24*time.Hour+5*time.Minute),
)
if err != nil {
return nil, err
}
return &s, nil
}
|