-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
53 lines (43 loc) · 1014 Bytes
/
utils.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
53
package main
import (
"net/url"
"path/filepath"
)
const (
urlSchemaHTTPType int = iota
urlSchemaSocketType
)
// getURL -
func getURL(urll, token, urlPath string, ttype int) (uu string, err error) {
u, err := url.Parse(urll)
if err != nil {
return
}
if token != "" {
values := u.Query()
values.Add("token", token)
u.RawQuery = values.Encode()
}
if urlPath != "" {
u.Path = filepath.Join(u.Path, urlPath)
}
switch ttype {
case urlSchemaHTTPType:
u.Scheme = "https"
case urlSchemaSocketType:
u.Scheme = "wss"
}
return u.String(), nil
}
// getStreamURL -
func getStreamURL() (string, error) {
return getURL(config.Gotify.URL, config.Gotify.Token, "stream", urlSchemaSocketType)
}
// getApplicationURL -
func getApplicationURL() (string, error) {
return getURL(config.Gotify.URL, config.Gotify.Token, "application", urlSchemaHTTPType)
}
// getImageURL -
func getImageURL(imagePath string) (string, error) {
return getURL(config.Gotify.URL, "", imagePath, urlSchemaHTTPType)
}