Skip to content

Commit

Permalink
Fix: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kavya498 committed Sep 29, 2021
1 parent 7a9d25e commit 2ef5ee1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
42 changes: 25 additions & 17 deletions api/container/containerv2/nlbdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (r *nlbdns) GetNLBDNSList(clusterNameOrID string) ([]NlbVPCListConfig, erro
var successV []interface{}
rawURL := fmt.Sprintf("/v2/nlb-dns/getNlbDNSList?cluster=%s", clusterNameOrID)
_, err := r.client.Get(rawURL, &successV)
if err != nil {
return success, err
}
if _, isVpc := successV[0].(map[string]interface{})["Nlb"]; isVpc {
bodyBytes, _ := json.Marshal(successV)
json.Unmarshal(bodyBytes, &success)
Expand All @@ -79,23 +82,28 @@ func (r *nlbdns) GetLocationNLBDNSList(location string) ([]NlbVPCListConfig, err
var successV []interface{}
rawURL := fmt.Sprintf("/v2/nlb-dns/getSatLocationSubdomains?controller=%s", location)
_, err := r.client.Get(rawURL, &successV)
if _, isVpc := successV[0].(map[string]interface{})["Nlb"]; isVpc {
bodyBytes, _ := json.Marshal(successV)
json.Unmarshal(bodyBytes, &success)
} else {
nlb := NlbVPCListConfig{}
for _, s := range successV {
b := s.(map[string]interface{})
nlb.SecretName = b["nlbSslSecretName"].(string)
nlb.SecretStatus = b["nlbSslSecretStatus"].(string)
nlb.Nlb.Cluster = b["clusterID"].(string)
nlb.Nlb.Type = b["nlbType"].(string)
nlb.Nlb.DnsType = b["nlbDnsType"].(string)
nlb.Nlb.NlbSubdomain = b["nlbHost"].(string)
nlb.Nlb.SecretNamespace = b["secretNamespace"].(string)
nlb.Nlb.NlbIPArray = b["nlbIPArray"].([]interface{})
nlb.Nlb.NlbMonitorState = b["nlbMonitorState"].(string)
success = append(success, nlb)
if err != nil {
return success, err
}
if len(successV) > 0 {
if _, isVpc := successV[0].(map[string]interface{})["Nlb"]; isVpc {
bodyBytes, _ := json.Marshal(successV)
json.Unmarshal(bodyBytes, &success)
} else {
nlb := NlbVPCListConfig{}
for _, s := range successV {
b := s.(map[string]interface{})
nlb.SecretName = b["nlbSslSecretName"].(string)
nlb.SecretStatus = b["nlbSslSecretStatus"].(string)
nlb.Nlb.Cluster = b["clusterID"].(string)
nlb.Nlb.Type = b["nlbType"].(string)
nlb.Nlb.DnsType = b["nlbDnsType"].(string)
nlb.Nlb.NlbSubdomain = b["nlbHost"].(string)
nlb.Nlb.SecretNamespace = b["secretNamespace"].(string)
nlb.Nlb.NlbIPArray = b["nlbIPArray"].([]interface{})
nlb.Nlb.NlbMonitorState = b["nlbMonitorState"].(string)
success = append(success, nlb)
}
}
}
return success, err
Expand Down
6 changes: 3 additions & 3 deletions endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ func NewEndpointLocator(region, visibility, file string) EndpointLocator {
if f := helpers.EnvFallBack([]string{"IBMCLOUD_ENDPOINTS_FILE", "IC_ENDPOINTS_FILE"}, file); f != "" {
jsonFile, err := os.Open(f)
if err != nil {
fmt.Printf("Unable to open File %s", err)
log.Fatalf("Unable to open endpoints file %s", err)
}
defer jsonFile.Close()
bytes, err := ioutil.ReadAll(jsonFile)
if err != nil {
fmt.Printf("Unable to read File %s", err)
log.Fatalf("Unable to read endpoints file %s", err)
}
err = json.Unmarshal([]byte(bytes), &fileMap)
if err != nil {
fmt.Printf("Unable to unmarshal File %s", err)
log.Fatalf("Unable to unmarshal endpoints file %s", err)
}
}
return &endpointLocator{region: region, visibility: visibility, endpointsFile: fileMap}
Expand Down

0 comments on commit 2ef5ee1

Please sign in to comment.