1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package gamelift
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/gamelift/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Retrieves the details for FlexMatch matchmaking rule sets. You can request all
16// existing rule sets for the Region, or provide a list of one or more rule set
17// names. When requesting multiple items, use the pagination parameters to retrieve
18// results as a set of sequential pages. If successful, a rule set is returned for
19// each requested name. Learn more
20//
21// * Build a rule set
22// (https://docs.aws.amazon.com/gamelift/latest/flexmatchguide/match-rulesets.html)
23//
24// Related
25// actions CreateMatchmakingConfiguration | DescribeMatchmakingConfigurations |
26// UpdateMatchmakingConfiguration | DeleteMatchmakingConfiguration |
27// CreateMatchmakingRuleSet | DescribeMatchmakingRuleSets |
28// ValidateMatchmakingRuleSet | DeleteMatchmakingRuleSet | All APIs by task
29// (https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets)
30func (c *Client) DescribeMatchmakingRuleSets(ctx context.Context, params *DescribeMatchmakingRuleSetsInput, optFns ...func(*Options)) (*DescribeMatchmakingRuleSetsOutput, error) {
31	if params == nil {
32		params = &DescribeMatchmakingRuleSetsInput{}
33	}
34
35	result, metadata, err := c.invokeOperation(ctx, "DescribeMatchmakingRuleSets", params, optFns, addOperationDescribeMatchmakingRuleSetsMiddlewares)
36	if err != nil {
37		return nil, err
38	}
39
40	out := result.(*DescribeMatchmakingRuleSetsOutput)
41	out.ResultMetadata = metadata
42	return out, nil
43}
44
45// Represents the input for a request operation.
46type DescribeMatchmakingRuleSetsInput struct {
47
48	// The maximum number of results to return. Use this parameter with NextToken to
49	// get results as a set of sequential pages.
50	Limit *int32
51
52	// A list of one or more matchmaking rule set names to retrieve details for. (Note:
53	// The rule set name is different from the optional "name" field in the rule set
54	// body.) You can use either the rule set name or ARN value.
55	Names []string
56
57	// A token that indicates the start of the next sequential page of results. Use the
58	// token that is returned with a previous call to this operation. To start at the
59	// beginning of the result set, do not specify a value.
60	NextToken *string
61}
62
63// Represents the returned data in response to a request operation.
64type DescribeMatchmakingRuleSetsOutput struct {
65
66	// A collection of requested matchmaking rule set objects.
67	//
68	// This member is required.
69	RuleSets []types.MatchmakingRuleSet
70
71	// A token that indicates where to resume retrieving results on the next call to
72	// this operation. If no token is returned, these results represent the end of the
73	// list.
74	NextToken *string
75
76	// Metadata pertaining to the operation's result.
77	ResultMetadata middleware.Metadata
78}
79
80func addOperationDescribeMatchmakingRuleSetsMiddlewares(stack *middleware.Stack, options Options) (err error) {
81	err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeMatchmakingRuleSets{}, middleware.After)
82	if err != nil {
83		return err
84	}
85	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeMatchmakingRuleSets{}, middleware.After)
86	if err != nil {
87		return err
88	}
89	if err = addSetLoggerMiddleware(stack, options); err != nil {
90		return err
91	}
92	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
93		return err
94	}
95	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
96		return err
97	}
98	if err = addResolveEndpointMiddleware(stack, options); err != nil {
99		return err
100	}
101	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
102		return err
103	}
104	if err = addRetryMiddlewares(stack, options); err != nil {
105		return err
106	}
107	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
108		return err
109	}
110	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
111		return err
112	}
113	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
114		return err
115	}
116	if err = addClientUserAgent(stack); err != nil {
117		return err
118	}
119	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
120		return err
121	}
122	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
123		return err
124	}
125	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeMatchmakingRuleSets(options.Region), middleware.Before); err != nil {
126		return err
127	}
128	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addResponseErrorMiddleware(stack); err != nil {
132		return err
133	}
134	if err = addRequestResponseLogging(stack, options); err != nil {
135		return err
136	}
137	return nil
138}
139
140// DescribeMatchmakingRuleSetsAPIClient is a client that implements the
141// DescribeMatchmakingRuleSets operation.
142type DescribeMatchmakingRuleSetsAPIClient interface {
143	DescribeMatchmakingRuleSets(context.Context, *DescribeMatchmakingRuleSetsInput, ...func(*Options)) (*DescribeMatchmakingRuleSetsOutput, error)
144}
145
146var _ DescribeMatchmakingRuleSetsAPIClient = (*Client)(nil)
147
148// DescribeMatchmakingRuleSetsPaginatorOptions is the paginator options for
149// DescribeMatchmakingRuleSets
150type DescribeMatchmakingRuleSetsPaginatorOptions struct {
151	// The maximum number of results to return. Use this parameter with NextToken to
152	// get results as a set of sequential pages.
153	Limit int32
154
155	// Set to true if pagination should stop if the service returns a pagination token
156	// that matches the most recent token provided to the service.
157	StopOnDuplicateToken bool
158}
159
160// DescribeMatchmakingRuleSetsPaginator is a paginator for
161// DescribeMatchmakingRuleSets
162type DescribeMatchmakingRuleSetsPaginator struct {
163	options   DescribeMatchmakingRuleSetsPaginatorOptions
164	client    DescribeMatchmakingRuleSetsAPIClient
165	params    *DescribeMatchmakingRuleSetsInput
166	nextToken *string
167	firstPage bool
168}
169
170// NewDescribeMatchmakingRuleSetsPaginator returns a new
171// DescribeMatchmakingRuleSetsPaginator
172func NewDescribeMatchmakingRuleSetsPaginator(client DescribeMatchmakingRuleSetsAPIClient, params *DescribeMatchmakingRuleSetsInput, optFns ...func(*DescribeMatchmakingRuleSetsPaginatorOptions)) *DescribeMatchmakingRuleSetsPaginator {
173	if params == nil {
174		params = &DescribeMatchmakingRuleSetsInput{}
175	}
176
177	options := DescribeMatchmakingRuleSetsPaginatorOptions{}
178	if params.Limit != nil {
179		options.Limit = *params.Limit
180	}
181
182	for _, fn := range optFns {
183		fn(&options)
184	}
185
186	return &DescribeMatchmakingRuleSetsPaginator{
187		options:   options,
188		client:    client,
189		params:    params,
190		firstPage: true,
191	}
192}
193
194// HasMorePages returns a boolean indicating whether more pages are available
195func (p *DescribeMatchmakingRuleSetsPaginator) HasMorePages() bool {
196	return p.firstPage || p.nextToken != nil
197}
198
199// NextPage retrieves the next DescribeMatchmakingRuleSets page.
200func (p *DescribeMatchmakingRuleSetsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeMatchmakingRuleSetsOutput, error) {
201	if !p.HasMorePages() {
202		return nil, fmt.Errorf("no more pages available")
203	}
204
205	params := *p.params
206	params.NextToken = p.nextToken
207
208	var limit *int32
209	if p.options.Limit > 0 {
210		limit = &p.options.Limit
211	}
212	params.Limit = limit
213
214	result, err := p.client.DescribeMatchmakingRuleSets(ctx, &params, optFns...)
215	if err != nil {
216		return nil, err
217	}
218	p.firstPage = false
219
220	prevToken := p.nextToken
221	p.nextToken = result.NextToken
222
223	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
224		p.nextToken = nil
225	}
226
227	return result, nil
228}
229
230func newServiceMetadataMiddleware_opDescribeMatchmakingRuleSets(region string) *awsmiddleware.RegisterServiceMetadata {
231	return &awsmiddleware.RegisterServiceMetadata{
232		Region:        region,
233		ServiceID:     ServiceID,
234		SigningName:   "gamelift",
235		OperationName: "DescribeMatchmakingRuleSets",
236	}
237}
238