1package types
2
3import (
4	"fmt"
5	"strings"
6
7	"github.com/sirupsen/logrus"
8)
9
10// DNSRecord defines what we understand as a DNSRecord
11type DNSRecord struct {
12	// Name the DNS host name
13	Name string `json:"name"`
14
15	// Value the value of this record
16	Value string `json:"value"`
17
18	// Type the record type
19	Type string `json:"type"`
20}
21
22// Check verifies if the DNS record satisfies certain conditions
23func (record *DNSRecord) Check() []string {
24	logrus.Infof("Record to check: '%v'", record)
25	emptyValueErrorMessage := "the value of field '%s' cannot be empty"
26	var errs []string
27
28	if strings.TrimSpace(record.Name) == "" {
29		errs = append(errs, fmt.Sprintf(emptyValueErrorMessage, "name"))
30	}
31
32	if strings.TrimSpace(record.Value) == "" {
33		errs = append(errs, fmt.Sprintf(emptyValueErrorMessage, "value"))
34	}
35
36	if strings.TrimSpace(record.Type) == "" {
37		errs = append(errs, fmt.Sprintf(emptyValueErrorMessage, "type"))
38	}
39	return errs
40}
41