1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package lexmodelsv2 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/lexmodelsv2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Gets a list of available bots. 16func (c *Client) ListBots(ctx context.Context, params *ListBotsInput, optFns ...func(*Options)) (*ListBotsOutput, error) { 17 if params == nil { 18 params = &ListBotsInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListBots", params, optFns, addOperationListBotsMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListBotsOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListBotsInput struct { 32 33 // Provides the specification of a filter used to limit the bots in the response to 34 // only those that match the filter specification. You can only specify one filter 35 // and one string to filter on. 36 Filters []types.BotFilter 37 38 // The maximum number of bots to return in each page of results. If there are fewer 39 // results than the maximum page size, only the actual number of results are 40 // returned. 41 MaxResults *int32 42 43 // If the response from the ListBots operation contains more results than specified 44 // in the maxResults parameter, a token is returned in the response. Use that token 45 // in the nextToken parameter to return the next page of results. 46 NextToken *string 47 48 // Specifies sorting parameters for the list of bots. You can specify that the list 49 // be sorted by bot name in ascending or descending order. 50 SortBy *types.BotSortBy 51} 52 53type ListBotsOutput struct { 54 55 // Summary information for the bots that meet the filter criteria specified in the 56 // request. The length of the list is specified in the maxResults parameter of the 57 // request. If there are more bots available, the nextToken field contains a token 58 // to the next page of results. 59 BotSummaries []types.BotSummary 60 61 // A token that indicates whether there are more results to return in a response to 62 // the ListBots operation. If the nextToken field is present, you send the contents 63 // as the nextToken parameter of a ListBots operation request to get the next page 64 // of results. 65 NextToken *string 66 67 // Metadata pertaining to the operation's result. 68 ResultMetadata middleware.Metadata 69} 70 71func addOperationListBotsMiddlewares(stack *middleware.Stack, options Options) (err error) { 72 err = stack.Serialize.Add(&awsRestjson1_serializeOpListBots{}, middleware.After) 73 if err != nil { 74 return err 75 } 76 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListBots{}, middleware.After) 77 if err != nil { 78 return err 79 } 80 if err = addSetLoggerMiddleware(stack, options); err != nil { 81 return err 82 } 83 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 84 return err 85 } 86 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 87 return err 88 } 89 if err = addResolveEndpointMiddleware(stack, options); err != nil { 90 return err 91 } 92 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 93 return err 94 } 95 if err = addRetryMiddlewares(stack, options); err != nil { 96 return err 97 } 98 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 99 return err 100 } 101 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 102 return err 103 } 104 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 105 return err 106 } 107 if err = addClientUserAgent(stack); err != nil { 108 return err 109 } 110 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 111 return err 112 } 113 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 114 return err 115 } 116 if err = addOpListBotsValidationMiddleware(stack); err != nil { 117 return err 118 } 119 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListBots(options.Region), middleware.Before); err != nil { 120 return err 121 } 122 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addResponseErrorMiddleware(stack); err != nil { 126 return err 127 } 128 if err = addRequestResponseLogging(stack, options); err != nil { 129 return err 130 } 131 return nil 132} 133 134// ListBotsAPIClient is a client that implements the ListBots operation. 135type ListBotsAPIClient interface { 136 ListBots(context.Context, *ListBotsInput, ...func(*Options)) (*ListBotsOutput, error) 137} 138 139var _ ListBotsAPIClient = (*Client)(nil) 140 141// ListBotsPaginatorOptions is the paginator options for ListBots 142type ListBotsPaginatorOptions struct { 143 // The maximum number of bots to return in each page of results. If there are fewer 144 // results than the maximum page size, only the actual number of results are 145 // returned. 146 Limit int32 147 148 // Set to true if pagination should stop if the service returns a pagination token 149 // that matches the most recent token provided to the service. 150 StopOnDuplicateToken bool 151} 152 153// ListBotsPaginator is a paginator for ListBots 154type ListBotsPaginator struct { 155 options ListBotsPaginatorOptions 156 client ListBotsAPIClient 157 params *ListBotsInput 158 nextToken *string 159 firstPage bool 160} 161 162// NewListBotsPaginator returns a new ListBotsPaginator 163func NewListBotsPaginator(client ListBotsAPIClient, params *ListBotsInput, optFns ...func(*ListBotsPaginatorOptions)) *ListBotsPaginator { 164 if params == nil { 165 params = &ListBotsInput{} 166 } 167 168 options := ListBotsPaginatorOptions{} 169 if params.MaxResults != nil { 170 options.Limit = *params.MaxResults 171 } 172 173 for _, fn := range optFns { 174 fn(&options) 175 } 176 177 return &ListBotsPaginator{ 178 options: options, 179 client: client, 180 params: params, 181 firstPage: true, 182 } 183} 184 185// HasMorePages returns a boolean indicating whether more pages are available 186func (p *ListBotsPaginator) HasMorePages() bool { 187 return p.firstPage || p.nextToken != nil 188} 189 190// NextPage retrieves the next ListBots page. 191func (p *ListBotsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListBotsOutput, error) { 192 if !p.HasMorePages() { 193 return nil, fmt.Errorf("no more pages available") 194 } 195 196 params := *p.params 197 params.NextToken = p.nextToken 198 199 var limit *int32 200 if p.options.Limit > 0 { 201 limit = &p.options.Limit 202 } 203 params.MaxResults = limit 204 205 result, err := p.client.ListBots(ctx, ¶ms, optFns...) 206 if err != nil { 207 return nil, err 208 } 209 p.firstPage = false 210 211 prevToken := p.nextToken 212 p.nextToken = result.NextToken 213 214 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 215 p.nextToken = nil 216 } 217 218 return result, nil 219} 220 221func newServiceMetadataMiddleware_opListBots(region string) *awsmiddleware.RegisterServiceMetadata { 222 return &awsmiddleware.RegisterServiceMetadata{ 223 Region: region, 224 ServiceID: ServiceID, 225 SigningName: "lex", 226 OperationName: "ListBots", 227 } 228} 229