func()

in cmd/sidecar/main.go [65:119]


func (po *probeOptions) Set(value string) error {
	splits := strings.Split(value, ",")
	if !(3 <= len(splits) && len(splits) <= 5) {
		return fmt.Errorf("invalid format to --probe")
	}

	option := sidecar.DNSProbeOption{
		Label:    splits[0],
		Server:   splits[1],
		Name:     splits[2],
		Interval: defaultProbeInterval,
		Type:     dns.TypeANY,
	}

	const labelRegexp = "^[a-zA-Z0-9_]+$"
	if !regexp.MustCompile(labelRegexp).MatchString(option.Label) {
		return fmt.Errorf("label must be of format %v", labelRegexp)
	}

	if !strings.Contains(option.Server, ":") {
		option.Server = option.Server + ":53"
	}

	if !strings.HasSuffix(option.Name, ".") {
		// dns package requires a fully qualified (e.g. terminal '.') name
		option.Name = option.Name + "."
	}

	if len(splits) >= 4 {
		if interval, err := strconv.Atoi(splits[3]); err == nil {
			option.Interval = time.Duration(interval) * time.Second
		} else {
			return err
		}
	}

	if len(splits) >= 5 {
		switch splits[4] {
		case "A":
			option.Type = dns.TypeA
		case "AAAA":
			option.Type = dns.TypeAAAA
		case "ANY":
			option.Type = dns.TypeANY
		case "SRV":
			option.Type = dns.TypeSRV
		default:
			return fmt.Errorf("invalid type for DNS: %v", splits[4])
		}
	}

	*po = append(*po, option)

	return nil
}