File size: 634 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
package label

import (
	"github.com/target/goalert/assignment"
	"github.com/target/goalert/validation/validate"
)

// A Label is a key-value pair assigned to a target.
type Label struct {
	Target assignment.Target
	Key    string `json:"key"`
	Value  string `json:"value"`
}

// Normalize will validate and normalize the label, returning a copy.
func (l Label) Normalize() (*Label, error) {
	return &l, validate.Many(
		validate.OneOf("TargetType", l.Target.TargetType(), assignment.TargetTypeService),
		validate.UUID("TargetID", l.Target.TargetID()),
		validate.LabelKey("Key", l.Key),
		validate.LabelValue("Value", l.Value),
	)
}