mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-22 07:53:38 +01:00
9d151fcdb4
* refactor: Partially break core package into dns, result and ssh packages * refactor: Move core package to config/endpoint * refactor: Fix warning about overlapping imported package name with endpoint variable * refactor: Rename EndpointStatus to Status * refactor: Merge result pkg back into endpoint pkg, because it makes more sense * refactor: Rename parameter r to result in Condition.evaluate * refactor: Rename parameter r to result * refactor: Revert accidental change to endpoint.TypeDNS * refactor: Rename parameter r to result * refactor: Merge util package into endpoint package * refactor: Rename parameter r to result
39 lines
1015 B
Go
39 lines
1015 B
Go
package dns
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
var (
|
|
// ErrDNSWithNoQueryName is the error with which gatus will panic if a dns is configured without query name
|
|
ErrDNSWithNoQueryName = errors.New("you must specify a query name in the DNS configuration")
|
|
|
|
// ErrDNSWithInvalidQueryType is the error with which gatus will panic if a dns is configured with invalid query type
|
|
ErrDNSWithInvalidQueryType = errors.New("invalid query type in the DNS configuration")
|
|
)
|
|
|
|
// Config for an Endpoint of type DNS
|
|
type Config struct {
|
|
// QueryType is the type for the DNS records like A, AAAA, CNAME...
|
|
QueryType string `yaml:"query-type"`
|
|
|
|
// QueryName is the query for DNS
|
|
QueryName string `yaml:"query-name"`
|
|
}
|
|
|
|
func (d *Config) ValidateAndSetDefault() error {
|
|
if len(d.QueryName) == 0 {
|
|
return ErrDNSWithNoQueryName
|
|
}
|
|
if !strings.HasSuffix(d.QueryName, ".") {
|
|
d.QueryName += "."
|
|
}
|
|
if _, ok := dns.StringToType[d.QueryType]; !ok {
|
|
return ErrDNSWithInvalidQueryType
|
|
}
|
|
return nil
|
|
}
|