forked from baidu/brcc-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl.go
executable file
·47 lines (39 loc) · 1.12 KB
/
url.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
package rcc
import (
"fmt"
"net/url"
"strings"
)
// rcc2.0 restApi文档:http://wiki.baidu.com/display/miniappb/Rest+Api
// 以及 http://wiki.baidu.com/pages/viewpage.action?pageId=1245297709
func httpUrl(ipOrAddr string) string {
if strings.HasPrefix(ipOrAddr, "http://") || strings.HasPrefix(ipOrAddr, "https://") {
return ipOrAddr
}
return fmt.Sprintf("http://%s", ipOrAddr)
}
func requestTokenUrl(conf *Conf) string {
return fmt.Sprintf("%s/api/auth",
httpUrl(conf.ServerUrl))
}
func apiEnvironment(conf *Conf) string {
return fmt.Sprintf("%s/api/environment/%s?token=%s",
httpUrl(conf.ServerUrl),
url.QueryEscape(conf.EnvName),
url.QueryEscape(conf.Token))
}
func apiVersion(conf *Conf) string {
return fmt.Sprintf("%s/api/version/%s?token=%s&environmentId=%d&versionName=%s",
httpUrl(conf.ServerUrl),
url.QueryEscape(conf.VersionName),
url.QueryEscape(conf.Token),
conf.EnvId,
url.QueryEscape(conf.VersionName),
)
}
func apiItems(conf *Conf, versionId int) string {
return fmt.Sprintf("%s/api/item?token=%s&versionId=%d",
httpUrl(conf.ServerUrl),
url.QueryEscape(conf.Token),
versionId)
}