aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/parse/transport.go
blob: f0cf1c249a1a2e33ca77539b9c975881f154d05a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package parse

import (
	"strings"

	"github.com/coredns/coredns/plugin/pkg/transport"
)

// Transport returns the transport defined in s and a string where the
// transport prefix is removed (if there was any). If no transport is defined
// we default to TransportDNS
func Transport(s string) (trans string, addr string) {
	switch {
	case strings.HasPrefix(s, transport.TLS+"://"):
		s = s[len(transport.TLS+"://"):]
		return transport.TLS, s

	case strings.HasPrefix(s, transport.DNS+"://"):
		s = s[len(transport.DNS+"://"):]
		return transport.DNS, s

	case strings.HasPrefix(s, transport.QUIC+"://"):
		s = s[len(transport.QUIC+"://"):]
		return transport.QUIC, s

	case strings.HasPrefix(s, transport.GRPC+"://"):
		s = s[len(transport.GRPC+"://"):]
		return transport.GRPC, s

	case strings.HasPrefix(s, transport.HTTPS+"://"):
		s = s[len(transport.HTTPS+"://"):]

		return transport.HTTPS, s
	case strings.HasPrefix(s, transport.UNIX+"://"):
		s = s[len(transport.UNIX+"://"):]
		return transport.UNIX, s
	}

	return transport.DNS, s
}