Skip to content

Commit

Permalink
Merge 'feat/support-vpc-endpoint' into 'master'
Browse files Browse the repository at this point in the history
feat: add endpoint

See merge request: !476
  • Loading branch information
sdk-liuzhaoliang committed Feb 17, 2025
2 parents 229d78f + b7abb03 commit 09ba30e
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 14 deletions.
2 changes: 1 addition & 1 deletion meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"lasted": "1.0.181",
"lasted": "1.0.182",
"meta_commit": "435201649d6fcd91781da16c49466fc8edf6b8eb"
}
2 changes: 1 addition & 1 deletion volcengine/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ package volcengine
const SDKName = "volcengine-go-sdk"

// SDKVersion is the version of this SDK
const SDKVersion = "1.0.181"
const SDKVersion = "1.0.182"
246 changes: 234 additions & 12 deletions volcengine/volcengineutil/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,226 @@ var endpoint = openPrefix + endpointSuffix
type RegionEndpointMap map[string]string

type ServiceEndpointInfo struct {
Service string
IsGlobal bool
GlobalEndpoint string
Service string
IsGlobal bool
GlobalEndpoint string
DefaultEndpoint string
RegionEndpointMap
}

var defaultEndpoint = map[string]*ServiceEndpointInfo{}
const (
regionCodeCNBeijingAutoDriving = "cn-beijing-autodriving"
)

var defaultEndpoint = map[string]*ServiceEndpointInfo{
"vke": {
Service: "vke",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "vke" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"Redis": {
Service: "Redis",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "redis" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"privatelink": {
Service: "privatelink",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "privatelink" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"vpc": {
Service: "vpc",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "vpc" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"RocketMQ": {
Service: "RocketMQ",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "rocketmq" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"Kafka": {
Service: "Kafka",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "kafka" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"rds_mysql": {
Service: "rds_mysql",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "rds-mysql" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"rds_postgresql": {
Service: "rds_postgresql",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "rds-postgresql" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"storage_ebs": {
Service: "storage_ebs",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "storage-ebs" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"clb": {
Service: "clb",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "clb" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"ecs": {
Service: "ecs",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "ecs" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"alb": {
Service: "alb",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "alb" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"FileNAS": {
Service: "FileNAS",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "filenas" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"configcenter": {
Service: "configcenter",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "configcenter" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"cr": {
Service: "cr",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "cr" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"sts": {
Service: "sts",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "sts" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"mongodb": {
Service: "mongodb",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "mongodb" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"transitrouter": {
Service: "transitrouter",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "transitrouter" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"Volc_Observe": {
Service: "Volc_Observe",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "volc-observe" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"dms": {
Service: "dms",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "dms" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"auto_scaling": {
Service: "auto_scaling",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "auto-scaling" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"directconnect": {
Service: "directconnect",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "directconnect" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
"kms": {
Service: "kms",
IsGlobal: false,
GlobalEndpoint: "",
DefaultEndpoint: endpoint,
RegionEndpointMap: RegionEndpointMap{
regionCodeCNBeijingAutoDriving: "kms" + separator + regionCodeCNBeijingAutoDriving + endpointSuffix,
},
},
}

// GetDefaultEndpointByServiceInfo retrieves the default endpoint for a given service and region.
//
Expand All @@ -73,21 +286,30 @@ var defaultEndpoint = map[string]*ServiceEndpointInfo{}
// Note: Ensure the `defaultEndpoint` map is properly populated with service and region endpoint
// information before calling this function.
func GetDefaultEndpointByServiceInfo(service string, regionCode string) *string {
resultEndpoint := endpoint
defaultEndpointInfo, sExist := defaultEndpoint[service]
if !sExist {
return &endpoint
return &resultEndpoint
}

isGlobal := defaultEndpointInfo.IsGlobal
if isGlobal {
return &defaultEndpointInfo.GlobalEndpoint
if len(defaultEndpointInfo.GlobalEndpoint) > 0 {
resultEndpoint = defaultEndpointInfo.GlobalEndpoint
return &resultEndpoint
}
} else {
regionEndpointMp := defaultEndpointInfo.RegionEndpointMap
regionEndpointStr, rExist := regionEndpointMp[regionCode]
if rExist {
resultEndpoint = regionEndpointStr
return &resultEndpoint
}
}

regionEndpointMp := defaultEndpointInfo.RegionEndpointMap
regionEndpointStr, rExist := regionEndpointMp[regionCode]
if !rExist {
return &endpoint
if len(defaultEndpointInfo.DefaultEndpoint) > 0 {
resultEndpoint = defaultEndpointInfo.DefaultEndpoint
return &resultEndpoint
}

return &regionEndpointStr
return &resultEndpoint
}

0 comments on commit 09ba30e

Please sign in to comment.