func RunExpire(client amt.AmtClient, hitId string, all bool) { if all { const maxHits = 100 if resp, err := client.SearchHITs("CreationTime", false, maxHits, 1); err != nil { fmt.Printf("Error: The AMT request failed: %v\n", err) return } else if len(resp.SearchHITsResults) > 0 && resp.SearchHITsResults[0].Request != nil && resp.SearchHITsResults[0].Request.Errors != nil { printObject(resp.SearchHITsResults[0].Request) } else if len(resp.SearchHITsResults[0].Hits) == 0 { fmt.Println("Found no HITs for this account") } else { for _, hit := range resp.SearchHITsResults[0].Hits { if hit.HITStatus == "Assignable" { fmt.Printf("Expire HIT %q with %d available assignments\n", hit.HITId, hit.NumberOfAssignmentsAvailable) RunExpire(client, string(hit.HITId), false) } } if len(resp.SearchHITsResults[0].Hits) == maxHits { fmt.Println("Retrieved the maximum number of HITs. Repeat the command to find any remaining HITs.") } } } else if resp, err := client.ForceExpireHIT(hitId); err != nil { fmt.Printf("Error: Could not expire HIT - %v", err) } else { printObject(resp) } }
func RunHits(client amt.AmtClient, sort string, desc bool, page, pageSize int) { if resp, err := client.SearchHITs(sort, !desc, pageSize, page); err != nil { fmt.Printf("Error: The AMT request failed: %v\n", err) return } else if len(resp.SearchHITsResults) > 0 && resp.SearchHITsResults[0].Request != nil && resp.SearchHITsResults[0].Request.Errors != nil { printObject(resp.SearchHITsResults[0].Request) } else if len(resp.SearchHITsResults[0].Hits) == 0 { fmt.Println("Found no HITs for this account") } else { for i, hit := range resp.SearchHITsResults[0].Hits { fmt.Printf("HIT %d/%d:\n", i+1, len(resp.SearchHITsResults)) printObject(hit) fmt.Println() } } }