-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/endpoint-config' into 'master'
Feat/endpoint config See merge request iaasng/volcengine-go-sdk!397
- Loading branch information
Showing
12 changed files
with
198 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/vendor/src/ | ||
doc | ||
.idea | ||
!/main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"lasted": "1.0.167", | ||
"lasted": "1.0.168", | ||
"meta_commit": "0e88bf7fed13f035b45fdb59b915aee4654f8fe6" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package endpoints | ||
|
||
import ( | ||
"io/ioutil" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
const ( | ||
separator = "." | ||
openPrefix = "open" | ||
endpointSuffix = separator + "volcengineapi.com" | ||
) | ||
|
||
var defaultEndpoint = openPrefix + endpointSuffix | ||
|
||
type RegionEndpointMap map[string]string | ||
|
||
type ServiceEndpointInfo struct { | ||
Service string `yaml:"Service"` | ||
IsGlobal bool `yaml:"IsGlobal"` | ||
GlobalEndpoint string `yaml:"GlobalEndpoint"` | ||
RegionEndpointMap `yaml:"RegionEndpointMap"` | ||
} | ||
|
||
type FileEndpointConfigResolver struct { | ||
Path string | ||
EndpointConfig map[string]*ServiceEndpointInfo | ||
} | ||
|
||
func (endpointResolver *FileEndpointConfigResolver) Load() error { | ||
file, err := ioutil.ReadFile(endpointResolver.Path) | ||
if err != nil { | ||
return err | ||
} | ||
config := make(map[string]*ServiceEndpointInfo) | ||
|
||
err = yaml.Unmarshal(file, config) | ||
if err != nil { | ||
return err | ||
} | ||
endpointResolver.EndpointConfig = config | ||
return nil | ||
} | ||
|
||
func (endpointResolver *FileEndpointConfigResolver) EndpointFor(service, region string, opts ...func(*Options)) (ResolvedEndpoint, error) { | ||
result := ResolvedEndpoint{} | ||
result.URL = defaultEndpoint | ||
defaultEndpointInfo, sExist := endpointResolver.EndpointConfig[service] | ||
if !sExist { | ||
return result, nil | ||
} | ||
|
||
isGlobal := defaultEndpointInfo.IsGlobal | ||
if isGlobal { | ||
result.URL = defaultEndpointInfo.GlobalEndpoint | ||
return result, nil | ||
} | ||
|
||
regionEndpointMp := defaultEndpointInfo.RegionEndpointMap | ||
regionEndpointStr, rExist := regionEndpointMp[region] | ||
if !rExist { | ||
return result, nil | ||
} | ||
|
||
result.URL = regionEndpointStr | ||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters