forked from qiniu/qshell
/
zone.go
98 lines (86 loc) · 2.05 KB
/
zone.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package qshell
import (
"qiniu/api.v6/conf"
)
type ZoneConfig struct {
UpHost string
RsHost string
RsfHost string
IovipHost string
ApiHost string
}
var (
DEFAULT_API_HOST = ZoneNBConfig.ApiHost
)
const (
ZoneNB = "nb"
ZoneBC = "bc"
ZoneHN = "hn"
ZoneAWS = "aws"
ZoneNA0 = "na0"
)
//zone all defaults to the service source site
var ZoneNBConfig = ZoneConfig{
UpHost: "http://up.qiniu.com",
RsHost: "http://rs.qiniu.com",
RsfHost: "http://rsf.qbox.me",
IovipHost: "http://iovip.qbox.me",
ApiHost: "http://api.qiniu.com",
}
var ZoneBCConfig = ZoneConfig{
UpHost: "http://up-z1.qiniu.com",
RsHost: "http://rs.qiniu.com",
RsfHost: "http://rsf-z1.qbox.me",
IovipHost: "http://iovip-z1.qbox.me",
ApiHost: "http://api-z1.qiniu.com",
}
var ZoneHNConfig = ZoneConfig{
UpHost: "http://up-z2.qiniu.com",
RsHost: "http://rs.qiniu.com",
RsfHost: "http://rsf-z2.qbox.me",
IovipHost: "http://iovip-z2.qbox.me",
ApiHost: "http://api-z2.qiniu.com",
}
var ZoneAWSConfig = ZoneConfig{
UpHost: "http://up.gdipper.com",
RsHost: "http://rs.gdipper.com",
RsfHost: "http://rsf.gdipper.com",
IovipHost: "http://io.gdipper.com",
ApiHost: "http://api.gdipper.com",
}
var ZoneNA0Config = ZoneConfig{
UpHost: "http://upload-na0.qiniu.com",
RsHost: "http://rs-na0.qbox.me",
RsfHost: "http://rsf-na0.qbox.me",
IovipHost: "http://iovip-na0.qbox.me",
ApiHost: "http://api-na0.qiniu.com",
}
func SetZone(zone string) {
var zoneConfig ZoneConfig
switch zone {
case ZoneAWS:
zoneConfig = ZoneAWSConfig
case ZoneBC:
zoneConfig = ZoneBCConfig
case ZoneHN:
zoneConfig = ZoneHNConfig
case ZoneNA0:
zoneConfig = ZoneNA0Config
default:
zoneConfig = ZoneNBConfig
}
conf.UP_HOST = zoneConfig.UpHost
conf.RS_HOST = zoneConfig.RsHost
conf.RSF_HOST = zoneConfig.RsfHost
conf.IO_HOST = zoneConfig.IovipHost
DEFAULT_API_HOST = zoneConfig.ApiHost
}
func IsValidZone(zone string) (valid bool) {
switch zone {
case ZoneNB, ZoneBC, ZoneHN, ZoneAWS, ZoneNA0:
valid = true
default:
valid = false
}
return
}