-
Notifications
You must be signed in to change notification settings - Fork 13
/
endpoint.go
66 lines (51 loc) · 1.24 KB
/
endpoint.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
54
55
56
57
58
59
60
61
62
63
64
65
66
package mixin
import (
"net/url"
"os"
"strings"
)
const (
DefaultApiHost = "https://api.mixin.one"
DefaultBlazeHost = "blaze.mixin.one"
ZeromeshApiHost = "https://mixin-api.zeromesh.net"
ZeromeshBlazeHost = "mixin-blaze.zeromesh.net"
EchoApiHost = "https://echo.yiplee.com"
)
func UseApiHost(host string) {
httpClient.HostURL = host
}
var (
blazeURL = buildBlazeURL(DefaultBlazeHost)
)
func buildBlazeURL(host string) string {
u := url.URL{Scheme: "wss", Host: host}
return u.String()
}
func UseBlazeHost(host string) {
blazeURL = buildBlazeURL(host)
}
func UseBlazeURL(rawURL string) {
u, err := url.Parse(rawURL)
if err != nil {
panic(err)
}
blazeURL = u.String()
}
func init() {
if _, ok := os.LookupEnv("MIXIN_SDK_USE_ZEROMESH"); ok {
UseApiHost(ZeromeshApiHost)
UseBlazeHost(ZeromeshBlazeHost)
}
if host, ok := os.LookupEnv("MIXIN_SDK_API_HOST"); ok && host != "" {
UseApiHost(host)
}
if host, ok := os.LookupEnv("MIXIN_SDK_BLAZE_HOST"); ok && host != "" {
UseBlazeHost(host)
}
if rawURL, ok := os.LookupEnv("MIXIN_SDK_BLAZE_URL"); ok && rawURL != "" {
UseBlazeURL(rawURL)
}
if hosts, ok := os.LookupEnv("MIXIN_SDK_MIXINNET_HOSTS"); ok && hosts != "" {
UseMixinNetHosts(strings.Split(hosts, ","))
}
}