-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
52 lines (45 loc) · 1022 Bytes
/
util.go
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
41
42
43
44
45
46
47
48
49
50
51
52
package services
import (
"errors"
"fmt"
"net"
"net/url"
"strings"
"time"
)
const (
Success = "Success!"
)
var ErrDidNotMatchExpectedOutput = errors.New("did not match Expected Output")
func tcpPortDial(host string, timeout time.Duration) error {
conn, err := net.DialTimeout("tcp", host, timeout)
if err != nil {
return fmt.Errorf("port was not open on a remote host: %w", err)
}
_ = conn.Close()
return nil
}
func IsSecure(s string) bool {
return ContainsString([]string{"https", "tls", "ssl", "ldaps"}, strings.ToLower(s))
}
func ContainsString(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
func ConstructURI(port, subdomain, host, path, scheme string) *url.URL {
if port == "" {
if strings.ToLower(scheme) == "https" {
port = "443"
} else {
port = "80"
}
}
if subdomain != "" && subdomain[len(subdomain)-1:] != "." {
subdomain += "."
}
return &url.URL{Path: path, Scheme: scheme, Host: subdomain + host + ":" + port}
}