1 回答

TA貢獻1854條經驗 獲得超8個贊
您可以在找到 時設置一個變量item。如果找不到,則print循環outside。
像這樣:
var found bool
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)
found = true
break
}
}
if !found {
fmt.Println("Unable to fine an API with the name " + apiName)
}
- 1 回答
- 0 關注
- 100 瀏覽
添加回答
舉報