feat: support SCTP & UDP as endpoint type (#352)
* feat: support SCTP & UDP as endpoint type * update README * modify endpoint type test for sctp & udp
This commit is contained in:
@ -36,6 +36,8 @@ const (
|
||||
|
||||
EndpointTypeDNS EndpointType = "DNS"
|
||||
EndpointTypeTCP EndpointType = "TCP"
|
||||
EndpointTypeSCTP EndpointType = "SCTP"
|
||||
EndpointTypeUDP EndpointType = "UDP"
|
||||
EndpointTypeICMP EndpointType = "ICMP"
|
||||
EndpointTypeSTARTTLS EndpointType = "STARTTLS"
|
||||
EndpointTypeTLS EndpointType = "TLS"
|
||||
@ -132,6 +134,10 @@ func (endpoint Endpoint) Type() EndpointType {
|
||||
return EndpointTypeDNS
|
||||
case strings.HasPrefix(endpoint.URL, "tcp://"):
|
||||
return EndpointTypeTCP
|
||||
case strings.HasPrefix(endpoint.URL, "sctp://"):
|
||||
return EndpointTypeSCTP
|
||||
case strings.HasPrefix(endpoint.URL, "udp://"):
|
||||
return EndpointTypeUDP
|
||||
case strings.HasPrefix(endpoint.URL, "icmp://"):
|
||||
return EndpointTypeICMP
|
||||
case strings.HasPrefix(endpoint.URL, "starttls://"):
|
||||
@ -329,6 +335,12 @@ func (endpoint *Endpoint) call(result *Result) {
|
||||
} else if endpointType == EndpointTypeTCP {
|
||||
result.Connected = client.CanCreateTCPConnection(strings.TrimPrefix(endpoint.URL, "tcp://"), endpoint.ClientConfig)
|
||||
result.Duration = time.Since(startTime)
|
||||
} else if endpointType == EndpointTypeUDP {
|
||||
result.Connected = client.CanCreateUDPConnection(strings.TrimPrefix(endpoint.URL, "udp://"), endpoint.ClientConfig)
|
||||
result.Duration = time.Since(startTime)
|
||||
} else if endpointType == EndpointTypeSCTP {
|
||||
result.Connected = client.CanCreateSCTPConnection(strings.TrimPrefix(endpoint.URL, "sctp://"), endpoint.ClientConfig)
|
||||
result.Duration = time.Since(startTime)
|
||||
} else if endpointType == EndpointTypeICMP {
|
||||
result.Connected, result.Duration = client.Ping(strings.TrimPrefix(endpoint.URL, "icmp://"), endpoint.ClientConfig)
|
||||
} else {
|
||||
|
@ -283,6 +283,18 @@ func TestEndpoint_Type(t *testing.T) {
|
||||
},
|
||||
want: EndpointTypeICMP,
|
||||
},
|
||||
{
|
||||
args: args{
|
||||
URL: "sctp://example.com",
|
||||
},
|
||||
want: EndpointTypeSCTP,
|
||||
},
|
||||
{
|
||||
args: args{
|
||||
URL: "udp://example.com",
|
||||
},
|
||||
want: EndpointTypeUDP,
|
||||
},
|
||||
{
|
||||
args: args{
|
||||
URL: "starttls://smtp.gmail.com:587",
|
||||
|
Reference in New Issue
Block a user