| 1 |
package oss |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
) |
| 6 |
|
| 7 |
|
| 8 |
type Region string |
| 9 |
|
| 10 |
|
| 11 |
const ( |
| 12 |
Hangzhou = Region("oss-cn-hangzhou") |
| 13 |
Qingdao = Region("oss-cn-qingdao") |
| 14 |
Beijing = Region("oss-cn-beijing") |
| 15 |
Hongkong = Region("oss-cn-hongkong") |
| 16 |
Shenzhen = Region("oss-cn-shenzhen") |
| 17 |
Shanghai = Region("oss-cn-shanghai") |
| 18 |
Zhangjiakou = Region("oss-cn-zhangjiakou") |
| 19 |
Huhehaote = Region("oss-cn-huhehaote") |
| 20 |
|
| 21 |
USWest1 = Region("oss-us-west-1") |
| 22 |
USEast1 = Region("oss-us-east-1") |
| 23 |
APSouthEast1 = Region("oss-ap-southeast-1") |
| 24 |
APNorthEast1 = Region("oss-ap-northeast-1") |
| 25 |
APSouthEast2 = Region("oss-ap-southeast-2") |
| 26 |
|
| 27 |
MEEast1 = Region("oss-me-east-1") |
| 28 |
|
| 29 |
EUCentral1 = Region("oss-eu-central-1") |
| 30 |
|
| 31 |
DefaultRegion = Hangzhou |
| 32 |
) |
| 33 |
|
| 34 |
|
| 35 |
func (r Region) GetEndpoint(internal bool, bucket string, secure bool) string { |
| 36 |
if internal { |
| 37 |
return r.GetInternalEndpoint(bucket, secure) |
| 38 |
} |
| 39 |
return r.GetInternetEndpoint(bucket, secure) |
| 40 |
} |
| 41 |
|
| 42 |
func getProtocol(secure bool) string { |
| 43 |
protocol := "http" |
| 44 |
if secure { |
| 45 |
protocol = "https" |
| 46 |
} |
| 47 |
return protocol |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
func (r Region) GetInternetEndpoint(bucket string, secure bool) string { |
| 52 |
protocol := getProtocol(secure) |
| 53 |
if bucket == "" { |
| 54 |
return fmt.Sprintf("%s://oss.aliyuncs.com", protocol) |
| 55 |
} |
| 56 |
return fmt.Sprintf("%s://%s.%s.aliyuncs.com", protocol, bucket, string(r)) |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
func (r Region) GetInternalEndpoint(bucket string, secure bool) string { |
| 61 |
protocol := getProtocol(secure) |
| 62 |
if bucket == "" { |
| 63 |
return fmt.Sprintf("%s://oss-internal.aliyuncs.com", protocol) |
| 64 |
} |
| 65 |
return fmt.Sprintf("%s://%s.%s-internal.aliyuncs.com", protocol, bucket, string(r)) |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
func (r Region) GetVPCInternalEndpoint(bucket string, secure bool) string { |
| 70 |
protocol := getProtocol(secure) |
| 71 |
if bucket == "" { |
| 72 |
return fmt.Sprintf("%s://vpc100-oss-cn-hangzhou.aliyuncs.com", protocol) |
| 73 |
} |
| 74 |
if r == USEast1 { |
| 75 |
return r.GetInternalEndpoint(bucket, secure) |
| 76 |
} else { |
| 77 |
return fmt.Sprintf("%s://%s.vpc100-%s.aliyuncs.com", protocol, bucket, string(r)) |
| 78 |
} |
| 79 |
} |