Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use json unmarshal instead of jmespath #917

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meta/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (a *Product) GetEndpoint(region string, client *sdk.Client) (string, error)
}

func (a *Product) TryGetEndpoints(region string, client *sdk.Client) (endpoint string, lcEndpoint string) {
endpoint, _ = a.RegionalEndpoints[region]
endpoint = a.RegionalEndpoints[region]

if a.LocationServiceCode != "" {
rp := endpoints.ResolveParam{
Expand Down
44 changes: 35 additions & 9 deletions meta/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"strings"

_ "embed"

jmespath "github.com/jmespath/go-jmespath"
)

type Repository struct {
Expand Down Expand Up @@ -79,16 +77,44 @@ func (a *Repository) GetApi(productCode string, version string, apiName string)
//go:embed versions.json
var versions []byte

// [
// {
// "code": "aegis",
// "styles": [
// {
// "style": "RPC",
// "version": "2016-11-11"
// }
// ]
// }
// ]

type ProductStyle struct {
Code string `json:"code"`
Styles []Style `json:"styles"`
}

type Style struct {
Style string `json:"style"`
Version string `json:"version"`
}

func (a *Repository) GetStyle(productCode, version string) (string, bool) {
v := new(interface{})
err := json.Unmarshal(versions, v)
productStyles := new([]ProductStyle)
err := json.Unmarshal(versions, &productStyles)
if err != nil {
return "", false
}
styles, _ := jmespath.Search("[?code=='"+productCode+"'].styles[]", *v)
style, _ := jmespath.Search("[?version=='"+version+"'].style", styles)
if len(style.([]interface{})) == 0 {
return "", false

for _, p := range *productStyles {
if p.Code == productCode {
for _, s := range p.Styles {
if s.Version == version {
return s.Style, true
}
}
}
}
return style.([]interface{})[0].(string), true

return "", false
}
Loading