forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsocket_utils.go
More file actions
42 lines (37 loc) · 912 Bytes
/
websocket_utils.go
File metadata and controls
42 lines (37 loc) · 912 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
41
42
package slack
import (
"fmt"
"log"
"net"
"net/url"
"strconv"
"time"
)
// JSONTimeString is an auxiliary type to allow us to format the time as we wish
type JSONTimeString string
// String converts the unix timestamp into a string
func (t JSONTimeString) String() string {
if t == "" {
return ""
}
floatN, err := strconv.ParseFloat(string(t), 64)
if err != nil {
log.Panicln(err)
return ""
}
timeStr := int64(floatN)
tm := time.Unix(int64(timeStr), 0)
return fmt.Sprintf("\"%s\"", tm.Format("Mon Jan _2"))
}
var portMapping = map[string]string{"ws": "80", "wss": "443"}
func websocketizeURLPort(orig string) (string, error) {
urlObj, err := url.ParseRequestURI(orig)
if err != nil {
return "", err
}
_, _, err = net.SplitHostPort(urlObj.Host)
if err != nil {
return urlObj.Scheme + "://" + urlObj.Host + ":" + portMapping[urlObj.Scheme] + urlObj.Path, nil
}
return orig, nil
}