In the code below if the user enters an incorrect API name to find the else
statement prints the "unable to find" message every time it goes through an item in the apis.Items
array. But I only want the error message printed once. Like after going through all the items in the apis.Items
array if there is no item with the name provided by the user the program should print the "unable to find" message. How do I achieve this. Ps: I'm new to this language
for _, item := range apis.Items {
if item.Name == apiName {
fmt.Printf("API ID found: %+v ", item.Id)
api_id := item.Id
cmd_2, err := exec.Command("aws", "apigateway", "get-export", "--rest-api-id", api_id, "--stage-name", stageName, "--export-type", "swagger", "/home/akshitha/Documents/" + apiName + ".json").Output()
if err != nil {
utils.HandleErrorAndExit("Error getting API swagger", err)
}
output := string(cmd_2[:])
fmt.Println(output)
break
}else {
fmt.Println("Unable to fine an API with the name " + apiName)
}
Aucun commentaire:
Enregistrer un commentaire