1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package iot 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/iot/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists your things. Use the attributeName and attributeValue parameters to filter 16// your things. For example, calling ListThings with attributeName=Color and 17// attributeValue=Red retrieves all things in the registry that contain an 18// attribute Color with the value Red. Requires permission to access the ListThings 19// (https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions) 20// action. You will not be charged for calling this API if an Access denied error 21// is returned. You will also not be charged if no attributes or pagination token 22// was provided in request and no pagination token and no results were returned. 23func (c *Client) ListThings(ctx context.Context, params *ListThingsInput, optFns ...func(*Options)) (*ListThingsOutput, error) { 24 if params == nil { 25 params = &ListThingsInput{} 26 } 27 28 result, metadata, err := c.invokeOperation(ctx, "ListThings", params, optFns, c.addOperationListThingsMiddlewares) 29 if err != nil { 30 return nil, err 31 } 32 33 out := result.(*ListThingsOutput) 34 out.ResultMetadata = metadata 35 return out, nil 36} 37 38// The input for the ListThings operation. 39type ListThingsInput struct { 40 41 // The attribute name used to search for things. 42 AttributeName *string 43 44 // The attribute value used to search for things. 45 AttributeValue *string 46 47 // The maximum number of results to return in this operation. 48 MaxResults *int32 49 50 // To retrieve the next set of results, the nextToken value from a previous 51 // response; otherwise null to receive the first set of results. 52 NextToken *string 53 54 // The name of the thing type used to search for things. 55 ThingTypeName *string 56 57 // When true, the action returns the thing resources with attribute values that 58 // start with the attributeValue provided. When false, or not present, the action 59 // returns only the thing resources with attribute values that match the entire 60 // attributeValue provided. 61 UsePrefixAttributeValue bool 62 63 noSmithyDocumentSerde 64} 65 66// The output from the ListThings operation. 67type ListThingsOutput struct { 68 69 // The token to use to get the next set of results. Will not be returned if 70 // operation has returned all results. 71 NextToken *string 72 73 // The things. 74 Things []types.ThingAttribute 75 76 // Metadata pertaining to the operation's result. 77 ResultMetadata middleware.Metadata 78 79 noSmithyDocumentSerde 80} 81 82func (c *Client) addOperationListThingsMiddlewares(stack *middleware.Stack, options Options) (err error) { 83 err = stack.Serialize.Add(&awsRestjson1_serializeOpListThings{}, middleware.After) 84 if err != nil { 85 return err 86 } 87 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListThings{}, middleware.After) 88 if err != nil { 89 return err 90 } 91 if err = addSetLoggerMiddleware(stack, options); err != nil { 92 return err 93 } 94 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 95 return err 96 } 97 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 98 return err 99 } 100 if err = addResolveEndpointMiddleware(stack, options); err != nil { 101 return err 102 } 103 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 104 return err 105 } 106 if err = addRetryMiddlewares(stack, options); err != nil { 107 return err 108 } 109 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 110 return err 111 } 112 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 113 return err 114 } 115 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 116 return err 117 } 118 if err = addClientUserAgent(stack); err != nil { 119 return err 120 } 121 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 122 return err 123 } 124 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 125 return err 126 } 127 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListThings(options.Region), middleware.Before); err != nil { 128 return err 129 } 130 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 131 return err 132 } 133 if err = addResponseErrorMiddleware(stack); err != nil { 134 return err 135 } 136 if err = addRequestResponseLogging(stack, options); err != nil { 137 return err 138 } 139 return nil 140} 141 142// ListThingsAPIClient is a client that implements the ListThings operation. 143type ListThingsAPIClient interface { 144 ListThings(context.Context, *ListThingsInput, ...func(*Options)) (*ListThingsOutput, error) 145} 146 147var _ ListThingsAPIClient = (*Client)(nil) 148 149// ListThingsPaginatorOptions is the paginator options for ListThings 150type ListThingsPaginatorOptions struct { 151 // The maximum number of results to return in this operation. 152 Limit int32 153 154 // Set to true if pagination should stop if the service returns a pagination token 155 // that matches the most recent token provided to the service. 156 StopOnDuplicateToken bool 157} 158 159// ListThingsPaginator is a paginator for ListThings 160type ListThingsPaginator struct { 161 options ListThingsPaginatorOptions 162 client ListThingsAPIClient 163 params *ListThingsInput 164 nextToken *string 165 firstPage bool 166} 167 168// NewListThingsPaginator returns a new ListThingsPaginator 169func NewListThingsPaginator(client ListThingsAPIClient, params *ListThingsInput, optFns ...func(*ListThingsPaginatorOptions)) *ListThingsPaginator { 170 if params == nil { 171 params = &ListThingsInput{} 172 } 173 174 options := ListThingsPaginatorOptions{} 175 if params.MaxResults != nil { 176 options.Limit = *params.MaxResults 177 } 178 179 for _, fn := range optFns { 180 fn(&options) 181 } 182 183 return &ListThingsPaginator{ 184 options: options, 185 client: client, 186 params: params, 187 firstPage: true, 188 } 189} 190 191// HasMorePages returns a boolean indicating whether more pages are available 192func (p *ListThingsPaginator) HasMorePages() bool { 193 return p.firstPage || p.nextToken != nil 194} 195 196// NextPage retrieves the next ListThings page. 197func (p *ListThingsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListThingsOutput, error) { 198 if !p.HasMorePages() { 199 return nil, fmt.Errorf("no more pages available") 200 } 201 202 params := *p.params 203 params.NextToken = p.nextToken 204 205 var limit *int32 206 if p.options.Limit > 0 { 207 limit = &p.options.Limit 208 } 209 params.MaxResults = limit 210 211 result, err := p.client.ListThings(ctx, ¶ms, optFns...) 212 if err != nil { 213 return nil, err 214 } 215 p.firstPage = false 216 217 prevToken := p.nextToken 218 p.nextToken = result.NextToken 219 220 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 221 p.nextToken = nil 222 } 223 224 return result, nil 225} 226 227func newServiceMetadataMiddleware_opListThings(region string) *awsmiddleware.RegisterServiceMetadata { 228 return &awsmiddleware.RegisterServiceMetadata{ 229 Region: region, 230 ServiceID: ServiceID, 231 SigningName: "execute-api", 232 OperationName: "ListThings", 233 } 234} 235