-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a505142
commit 64756ba
Showing
5 changed files
with
108 additions
and
8 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
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,81 @@ | ||
package newmeta | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
|
||
aliyunopenapimeta "github.com/aliyun/aliyun-cli/aliyun-openapi-meta" | ||
) | ||
|
||
// { | ||
// "products": [ | ||
// { | ||
// "code": "ARMS", | ||
// "name": "Application Real-Time Monitoring Service", | ||
// "version": "2019-08-08", | ||
// "endpointType": "regional", | ||
// "endpoints": { | ||
// "us-west-1": { | ||
// "regionId": "us-west-1", | ||
// "regionName": "US (Silicon Valley)", | ||
// "areaId": "europeAmerica", | ||
// "areaName": "Europe & Americas", | ||
// "public": "arms.us-west-1.aliyuncs.com", | ||
// "vpc": "arms-vpc.us-east-1.aliyuncs.com" | ||
// } | ||
// } | ||
// } | ||
// ] | ||
// } | ||
|
||
type ProductSet struct { | ||
Products []Product `json:"products"` | ||
} | ||
|
||
type Product struct { | ||
Code string `json:"code"` | ||
Name string `json:"name"` | ||
Version string `json:"version"` | ||
EndpointType string `json:"endpointType"` | ||
Endpoints map[string]Endpoint `json:"endpoints"` | ||
} | ||
|
||
type Endpoint struct { | ||
RegionId string `json:"regionId"` | ||
Name string `json:"regionName"` | ||
Version string `json:"areaId"` | ||
EndpointType string `json:"areaName"` | ||
Public string `json:"public"` | ||
VPC string `json:"vpc"` | ||
} | ||
|
||
func GetProductName(language, code string) (name string, err error) { | ||
content, err := GetMetadata(language, "/products.json") | ||
if err != nil { | ||
return | ||
} | ||
|
||
products := new(ProductSet) | ||
err = json.Unmarshal(content, &products) | ||
|
||
for _, p := range products.Products { | ||
if strings.EqualFold(p.Code, code) { | ||
name = strings.TrimSpace(p.Name) | ||
break | ||
} | ||
} | ||
|
||
return | ||
} | ||
|
||
func GetMetadataPrefix(language string) string { | ||
if language == "en" { | ||
return "en-US" | ||
} | ||
return "zh-CN" | ||
} | ||
|
||
func GetMetadata(language string, path string) (content []byte, err error) { | ||
content, err = aliyunopenapimeta.Metadatas.ReadFile(GetMetadataPrefix(language) + path) | ||
return | ||
} |
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,19 @@ | ||
package newmeta | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetMetadataPrefix(t *testing.T) { | ||
assert.Equal(t, "zh-CN", GetMetadataPrefix("")) | ||
assert.Equal(t, "en-US", GetMetadataPrefix("en")) | ||
assert.Equal(t, "zh-CN", GetMetadataPrefix("zh")) | ||
} | ||
|
||
func TestGetMetadata(t *testing.T) { | ||
content, err := GetMetadata("en", "/products.json") | ||
assert.Nil(t, err) | ||
assert.Greater(t, len(content), 100) | ||
} |
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