1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package iotthingsgraph 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/iotthingsgraph/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Searches for things associated with the specified entity. You can search by both 16// device and device model. For example, if two different devices, camera1 and 17// camera2, implement the camera device model, the user can associate thing1 to 18// camera1 and thing2 to camera2. SearchThings(camera2) will return only thing2, 19// but SearchThings(camera) will return both thing1 and thing2. This action 20// searches for exact matches and doesn't perform partial text matching. 21func (c *Client) SearchThings(ctx context.Context, params *SearchThingsInput, optFns ...func(*Options)) (*SearchThingsOutput, error) { 22 if params == nil { 23 params = &SearchThingsInput{} 24 } 25 26 result, metadata, err := c.invokeOperation(ctx, "SearchThings", params, optFns, addOperationSearchThingsMiddlewares) 27 if err != nil { 28 return nil, err 29 } 30 31 out := result.(*SearchThingsOutput) 32 out.ResultMetadata = metadata 33 return out, nil 34} 35 36type SearchThingsInput struct { 37 38 // The ID of the entity to which the things are associated. The IDs should be in 39 // the following format. urn:tdm:REGION/ACCOUNT ID/default:device:DEVICENAME 40 // 41 // This member is required. 42 EntityId *string 43 44 // The maximum number of results to return in the response. 45 MaxResults *int32 46 47 // The version of the user's namespace. Defaults to the latest version of the 48 // user's namespace. 49 NamespaceVersion *int64 50 51 // The string that specifies the next page of results. Use this when you're 52 // paginating results. 53 NextToken *string 54} 55 56type SearchThingsOutput struct { 57 58 // The string to specify as nextToken when you request the next page of results. 59 NextToken *string 60 61 // An array of things in the result set. 62 Things []types.Thing 63 64 // Metadata pertaining to the operation's result. 65 ResultMetadata middleware.Metadata 66} 67 68func addOperationSearchThingsMiddlewares(stack *middleware.Stack, options Options) (err error) { 69 err = stack.Serialize.Add(&awsAwsjson11_serializeOpSearchThings{}, middleware.After) 70 if err != nil { 71 return err 72 } 73 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpSearchThings{}, middleware.After) 74 if err != nil { 75 return err 76 } 77 if err = addSetLoggerMiddleware(stack, options); err != nil { 78 return err 79 } 80 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 81 return err 82 } 83 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 84 return err 85 } 86 if err = addResolveEndpointMiddleware(stack, options); err != nil { 87 return err 88 } 89 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 90 return err 91 } 92 if err = addRetryMiddlewares(stack, options); err != nil { 93 return err 94 } 95 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 96 return err 97 } 98 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 99 return err 100 } 101 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 102 return err 103 } 104 if err = addClientUserAgent(stack); err != nil { 105 return err 106 } 107 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 108 return err 109 } 110 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 111 return err 112 } 113 if err = addOpSearchThingsValidationMiddleware(stack); err != nil { 114 return err 115 } 116 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSearchThings(options.Region), middleware.Before); err != nil { 117 return err 118 } 119 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 120 return err 121 } 122 if err = addResponseErrorMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addRequestResponseLogging(stack, options); err != nil { 126 return err 127 } 128 return nil 129} 130 131// SearchThingsAPIClient is a client that implements the SearchThings operation. 132type SearchThingsAPIClient interface { 133 SearchThings(context.Context, *SearchThingsInput, ...func(*Options)) (*SearchThingsOutput, error) 134} 135 136var _ SearchThingsAPIClient = (*Client)(nil) 137 138// SearchThingsPaginatorOptions is the paginator options for SearchThings 139type SearchThingsPaginatorOptions struct { 140 // The maximum number of results to return in the response. 141 Limit int32 142 143 // Set to true if pagination should stop if the service returns a pagination token 144 // that matches the most recent token provided to the service. 145 StopOnDuplicateToken bool 146} 147 148// SearchThingsPaginator is a paginator for SearchThings 149type SearchThingsPaginator struct { 150 options SearchThingsPaginatorOptions 151 client SearchThingsAPIClient 152 params *SearchThingsInput 153 nextToken *string 154 firstPage bool 155} 156 157// NewSearchThingsPaginator returns a new SearchThingsPaginator 158func NewSearchThingsPaginator(client SearchThingsAPIClient, params *SearchThingsInput, optFns ...func(*SearchThingsPaginatorOptions)) *SearchThingsPaginator { 159 options := SearchThingsPaginatorOptions{} 160 if params.MaxResults != nil { 161 options.Limit = *params.MaxResults 162 } 163 164 for _, fn := range optFns { 165 fn(&options) 166 } 167 168 if params == nil { 169 params = &SearchThingsInput{} 170 } 171 172 return &SearchThingsPaginator{ 173 options: options, 174 client: client, 175 params: params, 176 firstPage: true, 177 } 178} 179 180// HasMorePages returns a boolean indicating whether more pages are available 181func (p *SearchThingsPaginator) HasMorePages() bool { 182 return p.firstPage || p.nextToken != nil 183} 184 185// NextPage retrieves the next SearchThings page. 186func (p *SearchThingsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*SearchThingsOutput, error) { 187 if !p.HasMorePages() { 188 return nil, fmt.Errorf("no more pages available") 189 } 190 191 params := *p.params 192 params.NextToken = p.nextToken 193 194 var limit *int32 195 if p.options.Limit > 0 { 196 limit = &p.options.Limit 197 } 198 params.MaxResults = limit 199 200 result, err := p.client.SearchThings(ctx, ¶ms, optFns...) 201 if err != nil { 202 return nil, err 203 } 204 p.firstPage = false 205 206 prevToken := p.nextToken 207 p.nextToken = result.NextToken 208 209 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 210 p.nextToken = nil 211 } 212 213 return result, nil 214} 215 216func newServiceMetadataMiddleware_opSearchThings(region string) *awsmiddleware.RegisterServiceMetadata { 217 return &awsmiddleware.RegisterServiceMetadata{ 218 Region: region, 219 ServiceID: ServiceID, 220 SigningName: "iotthingsgraph", 221 OperationName: "SearchThings", 222 } 223} 224