From 9304e9b5e29f72500d111567734c1a965379a86a Mon Sep 17 00:00:00 2001 From: Jiaqi Luo <6218999+jiaqiluo@users.noreply.github.com> Date: Mon, 4 Apr 2022 16:40:29 -0700 Subject: [PATCH] fixs some minor issues --- main.go | 2 +- pkg/config/get.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index ef0d96c..f95c78a 100644 --- a/main.go +++ b/main.go @@ -59,7 +59,7 @@ func main() { }, &cli.StringFlag{ Name: "app-name", - Usage: "the app for which the app default versions are for", + Usage: "the app for which to retrieve the app default versions", EnvVars: []string{"APP_NAME"}, Destination: &AppName, }, diff --git a/pkg/config/get.go b/pkg/config/get.go index 62b83a7..207bf78 100644 --- a/pkg/config/get.go +++ b/pkg/config/get.go @@ -45,10 +45,11 @@ func get(ctx context.Context, url Source) ([]byte, error) { if err != nil { return nil, err } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("status %v", resp.Status) } - defer resp.Body.Close() return ioutil.ReadAll(resp.Body) } @@ -165,8 +166,11 @@ func GetAppDefaultsConfig(content []byte, subKey, appName string) (*model.AppDef if err := yaml.Unmarshal(content, &data); err != nil { return nil, err } - data, _ = data[subKey].(map[string]interface{}) - if err := convert.ToObj(data, &allConfigs); err != nil { + subData, ok := data[subKey].(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("content at key %s expected to be map[string]interface{}, found %T instead", subKey, data[subKey]) + } + if err := convert.ToObj(subData, &allConfigs); err != nil { return nil, err } }