// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. package rekognition_test import ( "context" "fmt" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/aws/awserr" "github.com/aws/aws-sdk-go-v2/aws/external" "github.com/aws/aws-sdk-go-v2/service/rekognition" ) var _ aws.Config // To compare two images // // This operation compares the largest face detected in the source image with each face // detected in the target image. func ExampleClient_CompareFacesRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.CompareFacesInput{ SimilarityThreshold: aws.Float64(90.000000), SourceImage: &rekognition.Image{ S3Object: &rekognition.S3Object{ Bucket: aws.String("mybucket"), Name: aws.String("mysourceimage"), }, }, TargetImage: &rekognition.Image{ S3Object: &rekognition.S3Object{ Bucket: aws.String("mybucket"), Name: aws.String("mytargetimage"), }, }, } req := svc.CompareFacesRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeInvalidS3ObjectException: fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) case rekognition.ErrCodeImageTooLargeException: fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeInvalidImageFormatException: fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To create a collection // // This operation creates a Rekognition collection for storing image data. func ExampleClient_CreateCollectionRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.CreateCollectionInput{ CollectionId: aws.String("myphotos"), } req := svc.CreateCollectionRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeResourceAlreadyExistsException: fmt.Println(rekognition.ErrCodeResourceAlreadyExistsException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To delete a collection // // This operation deletes a Rekognition collection. func ExampleClient_DeleteCollectionRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.DeleteCollectionInput{ CollectionId: aws.String("myphotos"), } req := svc.DeleteCollectionRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeResourceNotFoundException: fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To delete a face // // This operation deletes one or more faces from a Rekognition collection. func ExampleClient_DeleteFacesRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.DeleteFacesInput{ CollectionId: aws.String("myphotos"), FaceIds: []string{ "ff43d742-0c13-5d16-a3e8-03d3f58e980b", }, } req := svc.DeleteFacesRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeResourceNotFoundException: fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To detect faces in an image // // This operation detects faces in an image stored in an AWS S3 bucket. func ExampleClient_DetectFacesRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.DetectFacesInput{ Image: &rekognition.Image{ S3Object: &rekognition.S3Object{ Bucket: aws.String("mybucket"), Name: aws.String("myphoto"), }, }, } req := svc.DetectFacesRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidS3ObjectException: fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeImageTooLargeException: fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeInvalidImageFormatException: fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To detect labels // // This operation detects labels in the supplied image func ExampleClient_DetectLabelsRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.DetectLabelsInput{ Image: &rekognition.Image{ S3Object: &rekognition.S3Object{ Bucket: aws.String("mybucket"), Name: aws.String("myphoto"), }, }, MaxLabels: aws.Int64(123), MinConfidence: aws.Float64(70.000000), } req := svc.DetectLabelsRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidS3ObjectException: fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeImageTooLargeException: fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeInvalidImageFormatException: fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To add a face to a collection // // This operation detects faces in an image and adds them to the specified Rekognition // collection. func ExampleClient_IndexFacesRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.IndexFacesInput{ CollectionId: aws.String("myphotos"), ExternalImageId: aws.String("myphotoid"), Image: &rekognition.Image{ S3Object: &rekognition.S3Object{ Bucket: aws.String("mybucket"), Name: aws.String("myphoto"), }, }, } req := svc.IndexFacesRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidS3ObjectException: fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeImageTooLargeException: fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeResourceNotFoundException: fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) case rekognition.ErrCodeInvalidImageFormatException: fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To list the collections // // This operation returns a list of Rekognition collections. func ExampleClient_ListCollectionsRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.ListCollectionsInput{} req := svc.ListCollectionsRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeInvalidPaginationTokenException: fmt.Println(rekognition.ErrCodeInvalidPaginationTokenException, aerr.Error()) case rekognition.ErrCodeResourceNotFoundException: fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To list the faces in a collection // // This operation lists the faces in a Rekognition collection. func ExampleClient_ListFacesRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.ListFacesInput{ CollectionId: aws.String("myphotos"), MaxResults: aws.Int64(20), } req := svc.ListFacesRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeInvalidPaginationTokenException: fmt.Println(rekognition.ErrCodeInvalidPaginationTokenException, aerr.Error()) case rekognition.ErrCodeResourceNotFoundException: fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To delete a face // // This operation searches for matching faces in the collection the supplied face belongs // to. func ExampleClient_SearchFacesRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.SearchFacesInput{ CollectionId: aws.String("myphotos"), FaceId: aws.String("70008e50-75e4-55d0-8e80-363fb73b3a14"), FaceMatchThreshold: aws.Float64(90.000000), MaxFaces: aws.Int64(10), } req := svc.SearchFacesRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeResourceNotFoundException: fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) } // To search for faces matching a supplied image // // This operation searches for faces in a Rekognition collection that match the largest // face in an S3 bucket stored image. func ExampleClient_SearchFacesByImageRequest_shared00() { cfg, err := external.LoadDefaultAWSConfig() if err != nil { panic("failed to load config, " + err.Error()) } svc := rekognition.New(cfg) input := &rekognition.SearchFacesByImageInput{ CollectionId: aws.String("myphotos"), FaceMatchThreshold: aws.Float64(95.000000), Image: &rekognition.Image{ S3Object: &rekognition.S3Object{ Bucket: aws.String("mybucket"), Name: aws.String("myphoto"), }, }, MaxFaces: aws.Int64(5), } req := svc.SearchFacesByImageRequest(input) result, err := req.Send(context.Background()) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case rekognition.ErrCodeInvalidS3ObjectException: fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) case rekognition.ErrCodeInvalidParameterException: fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) case rekognition.ErrCodeImageTooLargeException: fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) case rekognition.ErrCodeAccessDeniedException: fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) case rekognition.ErrCodeInternalServerError: fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) case rekognition.ErrCodeThrottlingException: fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) case rekognition.ErrCodeProvisionedThroughputExceededException: fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) case rekognition.ErrCodeResourceNotFoundException: fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) case rekognition.ErrCodeInvalidImageFormatException: fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) default: fmt.Println(aerr.Error()) } } else { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) } return } fmt.Println(result) }