1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package iotsitewise 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/iotsitewise/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Retrieves a paginated list of projects for an AWS IoT SiteWise Monitor portal. 16func (c *Client) ListProjects(ctx context.Context, params *ListProjectsInput, optFns ...func(*Options)) (*ListProjectsOutput, error) { 17 if params == nil { 18 params = &ListProjectsInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListProjects", params, optFns, addOperationListProjectsMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListProjectsOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListProjectsInput struct { 32 33 // The ID of the portal. 34 // 35 // This member is required. 36 PortalId *string 37 38 // The maximum number of results to be returned per paginated request. Default: 50 39 MaxResults *int32 40 41 // The token to be used for the next set of paginated results. 42 NextToken *string 43} 44 45type ListProjectsOutput struct { 46 47 // A list that summarizes each project in the portal. 48 // 49 // This member is required. 50 ProjectSummaries []types.ProjectSummary 51 52 // The token for the next set of results, or null if there are no additional 53 // results. 54 NextToken *string 55 56 // Metadata pertaining to the operation's result. 57 ResultMetadata middleware.Metadata 58} 59 60func addOperationListProjectsMiddlewares(stack *middleware.Stack, options Options) (err error) { 61 err = stack.Serialize.Add(&awsRestjson1_serializeOpListProjects{}, middleware.After) 62 if err != nil { 63 return err 64 } 65 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListProjects{}, middleware.After) 66 if err != nil { 67 return err 68 } 69 if err = addSetLoggerMiddleware(stack, options); err != nil { 70 return err 71 } 72 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 73 return err 74 } 75 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 76 return err 77 } 78 if err = addResolveEndpointMiddleware(stack, options); err != nil { 79 return err 80 } 81 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 82 return err 83 } 84 if err = addRetryMiddlewares(stack, options); err != nil { 85 return err 86 } 87 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 88 return err 89 } 90 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 91 return err 92 } 93 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 94 return err 95 } 96 if err = addClientUserAgent(stack); err != nil { 97 return err 98 } 99 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 100 return err 101 } 102 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 103 return err 104 } 105 if err = addEndpointPrefix_opListProjectsMiddleware(stack); err != nil { 106 return err 107 } 108 if err = addOpListProjectsValidationMiddleware(stack); err != nil { 109 return err 110 } 111 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListProjects(options.Region), middleware.Before); err != nil { 112 return err 113 } 114 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 115 return err 116 } 117 if err = addResponseErrorMiddleware(stack); err != nil { 118 return err 119 } 120 if err = addRequestResponseLogging(stack, options); err != nil { 121 return err 122 } 123 return nil 124} 125 126type endpointPrefix_opListProjectsMiddleware struct { 127} 128 129func (*endpointPrefix_opListProjectsMiddleware) ID() string { 130 return "EndpointHostPrefix" 131} 132 133func (m *endpointPrefix_opListProjectsMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) ( 134 out middleware.SerializeOutput, metadata middleware.Metadata, err error, 135) { 136 if smithyhttp.GetHostnameImmutable(ctx) || smithyhttp.IsEndpointHostPrefixDisabled(ctx) { 137 return next.HandleSerialize(ctx, in) 138 } 139 140 req, ok := in.Request.(*smithyhttp.Request) 141 if !ok { 142 return out, metadata, fmt.Errorf("unknown transport type %T", in.Request) 143 } 144 145 req.URL.Host = "monitor." + req.URL.Host 146 147 return next.HandleSerialize(ctx, in) 148} 149func addEndpointPrefix_opListProjectsMiddleware(stack *middleware.Stack) error { 150 return stack.Serialize.Insert(&endpointPrefix_opListProjectsMiddleware{}, `OperationSerializer`, middleware.After) 151} 152 153// ListProjectsAPIClient is a client that implements the ListProjects operation. 154type ListProjectsAPIClient interface { 155 ListProjects(context.Context, *ListProjectsInput, ...func(*Options)) (*ListProjectsOutput, error) 156} 157 158var _ ListProjectsAPIClient = (*Client)(nil) 159 160// ListProjectsPaginatorOptions is the paginator options for ListProjects 161type ListProjectsPaginatorOptions struct { 162 // The maximum number of results to be returned per paginated request. Default: 50 163 Limit int32 164 165 // Set to true if pagination should stop if the service returns a pagination token 166 // that matches the most recent token provided to the service. 167 StopOnDuplicateToken bool 168} 169 170// ListProjectsPaginator is a paginator for ListProjects 171type ListProjectsPaginator struct { 172 options ListProjectsPaginatorOptions 173 client ListProjectsAPIClient 174 params *ListProjectsInput 175 nextToken *string 176 firstPage bool 177} 178 179// NewListProjectsPaginator returns a new ListProjectsPaginator 180func NewListProjectsPaginator(client ListProjectsAPIClient, params *ListProjectsInput, optFns ...func(*ListProjectsPaginatorOptions)) *ListProjectsPaginator { 181 if params == nil { 182 params = &ListProjectsInput{} 183 } 184 185 options := ListProjectsPaginatorOptions{} 186 if params.MaxResults != nil { 187 options.Limit = *params.MaxResults 188 } 189 190 for _, fn := range optFns { 191 fn(&options) 192 } 193 194 return &ListProjectsPaginator{ 195 options: options, 196 client: client, 197 params: params, 198 firstPage: true, 199 } 200} 201 202// HasMorePages returns a boolean indicating whether more pages are available 203func (p *ListProjectsPaginator) HasMorePages() bool { 204 return p.firstPage || p.nextToken != nil 205} 206 207// NextPage retrieves the next ListProjects page. 208func (p *ListProjectsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListProjectsOutput, error) { 209 if !p.HasMorePages() { 210 return nil, fmt.Errorf("no more pages available") 211 } 212 213 params := *p.params 214 params.NextToken = p.nextToken 215 216 var limit *int32 217 if p.options.Limit > 0 { 218 limit = &p.options.Limit 219 } 220 params.MaxResults = limit 221 222 result, err := p.client.ListProjects(ctx, ¶ms, optFns...) 223 if err != nil { 224 return nil, err 225 } 226 p.firstPage = false 227 228 prevToken := p.nextToken 229 p.nextToken = result.NextToken 230 231 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 232 p.nextToken = nil 233 } 234 235 return result, nil 236} 237 238func newServiceMetadataMiddleware_opListProjects(region string) *awsmiddleware.RegisterServiceMetadata { 239 return &awsmiddleware.RegisterServiceMetadata{ 240 Region: region, 241 ServiceID: ServiceID, 242 SigningName: "iotsitewise", 243 OperationName: "ListProjects", 244 } 245} 246