forked from xdevplatform/xurl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoints.go
More file actions
37 lines (31 loc) · 1.02 KB
/
Copy pathendpoints.go
File metadata and controls
37 lines (31 loc) · 1.02 KB
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
package api
import (
"strings"
)
// StreamingEndpoints is a map of endpoint prefixes that should be streamed
var StreamingEndpoints = map[string]bool{
"/2/tweets/search/stream": true,
"/2/tweets/sample/stream": true,
"/2/tweets/sample10/stream": true,
"/2/tweets/firehose/stream": true,
"/2/tweets/firehose/stream/lang/en": true,
"/2/tweets/firehose/stream/lang/ja": true,
"/2/tweets/firehose/stream/lang/ko": true,
"/2/tweets/firehose/stream/lang/pt": true,
}
// IsStreamingEndpoint checks if an endpoint should be streamed
func IsStreamingEndpoint(endpoint string) bool {
path := endpoint
if strings.HasPrefix(strings.ToLower(endpoint), "http") {
parsedURL := strings.SplitN(endpoint, "/", 4)
if len(parsedURL) >= 4 {
path = "/" + parsedURL[3]
}
}
// Remove query parameters if present
if queryIndex := strings.Index(path, "?"); queryIndex != -1 {
path = path[:queryIndex]
}
normalizedEndpoint := strings.TrimSuffix(path, "/")
return StreamingEndpoints[normalizedEndpoint]
}