コード例 #1
0
ファイル: main.go プロジェクト: jesand/crowds
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)
	}
}