1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package chime 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/chime/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Lists all Channels created under a single Chime App as a paginated list. You can 16// specify filters to narrow results. Functionality & restrictions 17// 18// * Use privacy = 19// PUBLIC to retrieve all public channels in the account 20// 21// * Only an 22// AppInstanceAdmin can set privacy = PRIVATE to list the private channels in an 23// account. 24func (c *Client) ListChannels(ctx context.Context, params *ListChannelsInput, optFns ...func(*Options)) (*ListChannelsOutput, error) { 25 if params == nil { 26 params = &ListChannelsInput{} 27 } 28 29 result, metadata, err := c.invokeOperation(ctx, "ListChannels", params, optFns, addOperationListChannelsMiddlewares) 30 if err != nil { 31 return nil, err 32 } 33 34 out := result.(*ListChannelsOutput) 35 out.ResultMetadata = metadata 36 return out, nil 37} 38 39type ListChannelsInput struct { 40 41 // The ARN of the app instance. 42 // 43 // This member is required. 44 AppInstanceArn *string 45 46 // The maximum number of channels that you want to return. 47 MaxResults *int32 48 49 // The token passed by previous API calls until all requested channels are 50 // returned. 51 NextToken *string 52 53 // The privacy setting. PUBLIC retrieves all the public channels. PRIVATE retrieves 54 // private channels. Only an app instance administrator can retrieve private 55 // channels. 56 Privacy types.ChannelPrivacy 57} 58 59type ListChannelsOutput struct { 60 61 // The information about each channel. 62 Channels []types.ChannelSummary 63 64 // The token returned from previous API requests until the number of channels is 65 // reached. 66 NextToken *string 67 68 // Metadata pertaining to the operation's result. 69 ResultMetadata middleware.Metadata 70} 71 72func addOperationListChannelsMiddlewares(stack *middleware.Stack, options Options) (err error) { 73 err = stack.Serialize.Add(&awsRestjson1_serializeOpListChannels{}, middleware.After) 74 if err != nil { 75 return err 76 } 77 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListChannels{}, middleware.After) 78 if err != nil { 79 return err 80 } 81 if err = addSetLoggerMiddleware(stack, options); err != nil { 82 return err 83 } 84 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 85 return err 86 } 87 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 88 return err 89 } 90 if err = addResolveEndpointMiddleware(stack, options); err != nil { 91 return err 92 } 93 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 94 return err 95 } 96 if err = addRetryMiddlewares(stack, options); err != nil { 97 return err 98 } 99 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 100 return err 101 } 102 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 103 return err 104 } 105 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 106 return err 107 } 108 if err = addClientUserAgent(stack); err != nil { 109 return err 110 } 111 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 112 return err 113 } 114 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 115 return err 116 } 117 if err = addEndpointPrefix_opListChannelsMiddleware(stack); err != nil { 118 return err 119 } 120 if err = addOpListChannelsValidationMiddleware(stack); err != nil { 121 return err 122 } 123 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListChannels(options.Region), middleware.Before); err != nil { 124 return err 125 } 126 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 127 return err 128 } 129 if err = addResponseErrorMiddleware(stack); err != nil { 130 return err 131 } 132 if err = addRequestResponseLogging(stack, options); err != nil { 133 return err 134 } 135 return nil 136} 137 138type endpointPrefix_opListChannelsMiddleware struct { 139} 140 141func (*endpointPrefix_opListChannelsMiddleware) ID() string { 142 return "EndpointHostPrefix" 143} 144 145func (m *endpointPrefix_opListChannelsMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) ( 146 out middleware.SerializeOutput, metadata middleware.Metadata, err error, 147) { 148 if smithyhttp.GetHostnameImmutable(ctx) || smithyhttp.IsEndpointHostPrefixDisabled(ctx) { 149 return next.HandleSerialize(ctx, in) 150 } 151 152 req, ok := in.Request.(*smithyhttp.Request) 153 if !ok { 154 return out, metadata, fmt.Errorf("unknown transport type %T", in.Request) 155 } 156 157 req.URL.Host = "messaging-" + req.URL.Host 158 159 return next.HandleSerialize(ctx, in) 160} 161func addEndpointPrefix_opListChannelsMiddleware(stack *middleware.Stack) error { 162 return stack.Serialize.Insert(&endpointPrefix_opListChannelsMiddleware{}, `OperationSerializer`, middleware.After) 163} 164 165// ListChannelsAPIClient is a client that implements the ListChannels operation. 166type ListChannelsAPIClient interface { 167 ListChannels(context.Context, *ListChannelsInput, ...func(*Options)) (*ListChannelsOutput, error) 168} 169 170var _ ListChannelsAPIClient = (*Client)(nil) 171 172// ListChannelsPaginatorOptions is the paginator options for ListChannels 173type ListChannelsPaginatorOptions struct { 174 // The maximum number of channels that you want to return. 175 Limit int32 176 177 // Set to true if pagination should stop if the service returns a pagination token 178 // that matches the most recent token provided to the service. 179 StopOnDuplicateToken bool 180} 181 182// ListChannelsPaginator is a paginator for ListChannels 183type ListChannelsPaginator struct { 184 options ListChannelsPaginatorOptions 185 client ListChannelsAPIClient 186 params *ListChannelsInput 187 nextToken *string 188 firstPage bool 189} 190 191// NewListChannelsPaginator returns a new ListChannelsPaginator 192func NewListChannelsPaginator(client ListChannelsAPIClient, params *ListChannelsInput, optFns ...func(*ListChannelsPaginatorOptions)) *ListChannelsPaginator { 193 options := ListChannelsPaginatorOptions{} 194 if params.MaxResults != nil { 195 options.Limit = *params.MaxResults 196 } 197 198 for _, fn := range optFns { 199 fn(&options) 200 } 201 202 if params == nil { 203 params = &ListChannelsInput{} 204 } 205 206 return &ListChannelsPaginator{ 207 options: options, 208 client: client, 209 params: params, 210 firstPage: true, 211 } 212} 213 214// HasMorePages returns a boolean indicating whether more pages are available 215func (p *ListChannelsPaginator) HasMorePages() bool { 216 return p.firstPage || p.nextToken != nil 217} 218 219// NextPage retrieves the next ListChannels page. 220func (p *ListChannelsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListChannelsOutput, error) { 221 if !p.HasMorePages() { 222 return nil, fmt.Errorf("no more pages available") 223 } 224 225 params := *p.params 226 params.NextToken = p.nextToken 227 228 var limit *int32 229 if p.options.Limit > 0 { 230 limit = &p.options.Limit 231 } 232 params.MaxResults = limit 233 234 result, err := p.client.ListChannels(ctx, ¶ms, optFns...) 235 if err != nil { 236 return nil, err 237 } 238 p.firstPage = false 239 240 prevToken := p.nextToken 241 p.nextToken = result.NextToken 242 243 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 244 p.nextToken = nil 245 } 246 247 return result, nil 248} 249 250func newServiceMetadataMiddleware_opListChannels(region string) *awsmiddleware.RegisterServiceMetadata { 251 return &awsmiddleware.RegisterServiceMetadata{ 252 Region: region, 253 ServiceID: ServiceID, 254 SigningName: "chime", 255 OperationName: "ListChannels", 256 } 257} 258