blob: 460e91dc56e50529df5790c81f661c84416f9dd6 (
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
|
package send
import (
"fmt"
"net/url"
"strings"
)
func parseScheme(uri *url.URL) (protocol string, auth string, err error) {
protocol = ""
auth = "plain"
if uri.Scheme != "" {
parts := strings.Split(uri.Scheme, "+")
switch len(parts) {
case 1:
protocol = parts[0]
case 2:
if parts[1] == "insecure" {
protocol = uri.Scheme
} else {
protocol = parts[0]
auth = parts[1]
}
case 3:
protocol = parts[0] + "+" + parts[1]
auth = parts[2]
default:
return "", "", fmt.Errorf("Unknown scheme %s", uri.Scheme)
}
}
return protocol, auth, nil
}
|