forked from matrix-org/sliding-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
40 lines (35 loc) · 791 Bytes
/
util.go
File metadata and controls
40 lines (35 loc) · 791 Bytes
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 internal
import (
"context"
"net"
"net/http"
"strings"
)
// Keys returns a slice containing copies of the keys of the given map, in no particular
// order.
func Keys[K comparable, V any](m map[K]V) []K {
if m == nil {
return nil
}
output := make([]K, 0, len(m))
for key := range m {
output = append(output, key)
}
return output
}
func IsUnixSocket(httpOrUnixStr string) bool {
return strings.HasPrefix(httpOrUnixStr, "/")
}
func UnixTransport(httpOrUnixStr string) *http.Transport {
return &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", httpOrUnixStr)
},
}
}
func GetBaseURL(httpOrUnixStr string) string {
if IsUnixSocket(httpOrUnixStr) {
return "http://unix"
}
return httpOrUnixStr
}