1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package rekognition 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/rekognition/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Gets face detection results for a Amazon Rekognition Video analysis started by 16// StartFaceDetection. Face detection with Amazon Rekognition Video is an 17// asynchronous operation. You start face detection by calling StartFaceDetection 18// which returns a job identifier (JobId). When the face detection operation 19// finishes, Amazon Rekognition Video publishes a completion status to the Amazon 20// Simple Notification Service topic registered in the initial call to 21// StartFaceDetection. To get the results of the face detection operation, first 22// check that the status value published to the Amazon SNS topic is SUCCEEDED. If 23// so, call GetFaceDetection and pass the job identifier (JobId) from the initial 24// call to StartFaceDetection. GetFaceDetection returns an array of detected faces 25// (Faces) sorted by the time the faces were detected. Use MaxResults parameter to 26// limit the number of labels returned. If there are more results than specified in 27// MaxResults, the value of NextToken in the operation response contains a 28// pagination token for getting the next set of results. To get the next page of 29// results, call GetFaceDetection and populate the NextToken request parameter with 30// the token value returned from the previous call to GetFaceDetection. 31func (c *Client) GetFaceDetection(ctx context.Context, params *GetFaceDetectionInput, optFns ...func(*Options)) (*GetFaceDetectionOutput, error) { 32 if params == nil { 33 params = &GetFaceDetectionInput{} 34 } 35 36 result, metadata, err := c.invokeOperation(ctx, "GetFaceDetection", params, optFns, addOperationGetFaceDetectionMiddlewares) 37 if err != nil { 38 return nil, err 39 } 40 41 out := result.(*GetFaceDetectionOutput) 42 out.ResultMetadata = metadata 43 return out, nil 44} 45 46type GetFaceDetectionInput struct { 47 48 // Unique identifier for the face detection job. The JobId is returned from 49 // StartFaceDetection. 50 // 51 // This member is required. 52 JobId *string 53 54 // Maximum number of results to return per paginated call. The largest value you 55 // can specify is 1000. If you specify a value greater than 1000, a maximum of 1000 56 // results is returned. The default value is 1000. 57 MaxResults *int32 58 59 // If the previous response was incomplete (because there are more faces to 60 // retrieve), Amazon Rekognition Video returns a pagination token in the response. 61 // You can use this pagination token to retrieve the next set of faces. 62 NextToken *string 63} 64 65type GetFaceDetectionOutput struct { 66 67 // An array of faces detected in the video. Each element contains a detected face's 68 // details and the time, in milliseconds from the start of the video, the face was 69 // detected. 70 Faces []types.FaceDetection 71 72 // The current status of the face detection job. 73 JobStatus types.VideoJobStatus 74 75 // If the response is truncated, Amazon Rekognition returns this token that you can 76 // use in the subsequent request to retrieve the next set of faces. 77 NextToken *string 78 79 // If the job fails, StatusMessage provides a descriptive error message. 80 StatusMessage *string 81 82 // Information about a video that Amazon Rekognition Video analyzed. Videometadata 83 // is returned in every page of paginated responses from a Amazon Rekognition video 84 // operation. 85 VideoMetadata *types.VideoMetadata 86 87 // Metadata pertaining to the operation's result. 88 ResultMetadata middleware.Metadata 89} 90 91func addOperationGetFaceDetectionMiddlewares(stack *middleware.Stack, options Options) (err error) { 92 err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetFaceDetection{}, middleware.After) 93 if err != nil { 94 return err 95 } 96 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetFaceDetection{}, middleware.After) 97 if err != nil { 98 return err 99 } 100 if err = addSetLoggerMiddleware(stack, options); err != nil { 101 return err 102 } 103 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 104 return err 105 } 106 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 107 return err 108 } 109 if err = addResolveEndpointMiddleware(stack, options); err != nil { 110 return err 111 } 112 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 113 return err 114 } 115 if err = addRetryMiddlewares(stack, options); err != nil { 116 return err 117 } 118 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 119 return err 120 } 121 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 122 return err 123 } 124 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 125 return err 126 } 127 if err = addClientUserAgent(stack); err != nil { 128 return err 129 } 130 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 131 return err 132 } 133 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 134 return err 135 } 136 if err = addOpGetFaceDetectionValidationMiddleware(stack); err != nil { 137 return err 138 } 139 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetFaceDetection(options.Region), middleware.Before); err != nil { 140 return err 141 } 142 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 143 return err 144 } 145 if err = addResponseErrorMiddleware(stack); err != nil { 146 return err 147 } 148 if err = addRequestResponseLogging(stack, options); err != nil { 149 return err 150 } 151 return nil 152} 153 154// GetFaceDetectionAPIClient is a client that implements the GetFaceDetection 155// operation. 156type GetFaceDetectionAPIClient interface { 157 GetFaceDetection(context.Context, *GetFaceDetectionInput, ...func(*Options)) (*GetFaceDetectionOutput, error) 158} 159 160var _ GetFaceDetectionAPIClient = (*Client)(nil) 161 162// GetFaceDetectionPaginatorOptions is the paginator options for GetFaceDetection 163type GetFaceDetectionPaginatorOptions struct { 164 // Maximum number of results to return per paginated call. The largest value you 165 // can specify is 1000. If you specify a value greater than 1000, a maximum of 1000 166 // results is returned. The default value is 1000. 167 Limit int32 168 169 // Set to true if pagination should stop if the service returns a pagination token 170 // that matches the most recent token provided to the service. 171 StopOnDuplicateToken bool 172} 173 174// GetFaceDetectionPaginator is a paginator for GetFaceDetection 175type GetFaceDetectionPaginator struct { 176 options GetFaceDetectionPaginatorOptions 177 client GetFaceDetectionAPIClient 178 params *GetFaceDetectionInput 179 nextToken *string 180 firstPage bool 181} 182 183// NewGetFaceDetectionPaginator returns a new GetFaceDetectionPaginator 184func NewGetFaceDetectionPaginator(client GetFaceDetectionAPIClient, params *GetFaceDetectionInput, optFns ...func(*GetFaceDetectionPaginatorOptions)) *GetFaceDetectionPaginator { 185 if params == nil { 186 params = &GetFaceDetectionInput{} 187 } 188 189 options := GetFaceDetectionPaginatorOptions{} 190 if params.MaxResults != nil { 191 options.Limit = *params.MaxResults 192 } 193 194 for _, fn := range optFns { 195 fn(&options) 196 } 197 198 return &GetFaceDetectionPaginator{ 199 options: options, 200 client: client, 201 params: params, 202 firstPage: true, 203 } 204} 205 206// HasMorePages returns a boolean indicating whether more pages are available 207func (p *GetFaceDetectionPaginator) HasMorePages() bool { 208 return p.firstPage || p.nextToken != nil 209} 210 211// NextPage retrieves the next GetFaceDetection page. 212func (p *GetFaceDetectionPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetFaceDetectionOutput, error) { 213 if !p.HasMorePages() { 214 return nil, fmt.Errorf("no more pages available") 215 } 216 217 params := *p.params 218 params.NextToken = p.nextToken 219 220 var limit *int32 221 if p.options.Limit > 0 { 222 limit = &p.options.Limit 223 } 224 params.MaxResults = limit 225 226 result, err := p.client.GetFaceDetection(ctx, ¶ms, optFns...) 227 if err != nil { 228 return nil, err 229 } 230 p.firstPage = false 231 232 prevToken := p.nextToken 233 p.nextToken = result.NextToken 234 235 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 236 p.nextToken = nil 237 } 238 239 return result, nil 240} 241 242func newServiceMetadataMiddleware_opGetFaceDetection(region string) *awsmiddleware.RegisterServiceMetadata { 243 return &awsmiddleware.RegisterServiceMetadata{ 244 Region: region, 245 ServiceID: ServiceID, 246 SigningName: "rekognition", 247 OperationName: "GetFaceDetection", 248 } 249} 250