1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package groundstation
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/groundstation/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns a list of ground stations.
16func (c *Client) ListGroundStations(ctx context.Context, params *ListGroundStationsInput, optFns ...func(*Options)) (*ListGroundStationsOutput, error) {
17	if params == nil {
18		params = &ListGroundStationsInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListGroundStations", params, optFns, addOperationListGroundStationsMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListGroundStationsOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31//
32type ListGroundStationsInput struct {
33
34	// Maximum number of ground stations returned.
35	MaxResults *int32
36
37	// Next token that can be supplied in the next call to get the next page of ground
38	// stations.
39	NextToken *string
40
41	// Satellite ID to retrieve on-boarded ground stations.
42	SatelliteId *string
43}
44
45//
46type ListGroundStationsOutput struct {
47
48	// List of ground stations.
49	GroundStationList []types.GroundStationData
50
51	// Next token that can be supplied in the next call to get the next page of ground
52	// stations.
53	NextToken *string
54
55	// Metadata pertaining to the operation's result.
56	ResultMetadata middleware.Metadata
57}
58
59func addOperationListGroundStationsMiddlewares(stack *middleware.Stack, options Options) (err error) {
60	err = stack.Serialize.Add(&awsRestjson1_serializeOpListGroundStations{}, middleware.After)
61	if err != nil {
62		return err
63	}
64	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListGroundStations{}, middleware.After)
65	if err != nil {
66		return err
67	}
68	if err = addSetLoggerMiddleware(stack, options); err != nil {
69		return err
70	}
71	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
72		return err
73	}
74	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
75		return err
76	}
77	if err = addResolveEndpointMiddleware(stack, options); err != nil {
78		return err
79	}
80	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
81		return err
82	}
83	if err = addRetryMiddlewares(stack, options); err != nil {
84		return err
85	}
86	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
87		return err
88	}
89	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
90		return err
91	}
92	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
93		return err
94	}
95	if err = addClientUserAgent(stack); err != nil {
96		return err
97	}
98	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
102		return err
103	}
104	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
105		return err
106	}
107	if err = addResponseErrorMiddleware(stack); err != nil {
108		return err
109	}
110	if err = addRequestResponseLogging(stack, options); err != nil {
111		return err
112	}
113	return nil
114}
115
116// ListGroundStationsAPIClient is a client that implements the ListGroundStations
117// operation.
118type ListGroundStationsAPIClient interface {
119	ListGroundStations(context.Context, *ListGroundStationsInput, ...func(*Options)) (*ListGroundStationsOutput, error)
120}
121
122var _ ListGroundStationsAPIClient = (*Client)(nil)
123
124// ListGroundStationsPaginatorOptions is the paginator options for
125// ListGroundStations
126type ListGroundStationsPaginatorOptions struct {
127	// Maximum number of ground stations returned.
128	Limit int32
129
130	// Set to true if pagination should stop if the service returns a pagination token
131	// that matches the most recent token provided to the service.
132	StopOnDuplicateToken bool
133}
134
135// ListGroundStationsPaginator is a paginator for ListGroundStations
136type ListGroundStationsPaginator struct {
137	options   ListGroundStationsPaginatorOptions
138	client    ListGroundStationsAPIClient
139	params    *ListGroundStationsInput
140	nextToken *string
141	firstPage bool
142}
143
144// NewListGroundStationsPaginator returns a new ListGroundStationsPaginator
145func NewListGroundStationsPaginator(client ListGroundStationsAPIClient, params *ListGroundStationsInput, optFns ...func(*ListGroundStationsPaginatorOptions)) *ListGroundStationsPaginator {
146	options := ListGroundStationsPaginatorOptions{}
147	if params.MaxResults != nil {
148		options.Limit = *params.MaxResults
149	}
150
151	for _, fn := range optFns {
152		fn(&options)
153	}
154
155	if params == nil {
156		params = &ListGroundStationsInput{}
157	}
158
159	return &ListGroundStationsPaginator{
160		options:   options,
161		client:    client,
162		params:    params,
163		firstPage: true,
164	}
165}
166
167// HasMorePages returns a boolean indicating whether more pages are available
168func (p *ListGroundStationsPaginator) HasMorePages() bool {
169	return p.firstPage || p.nextToken != nil
170}
171
172// NextPage retrieves the next ListGroundStations page.
173func (p *ListGroundStationsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListGroundStationsOutput, error) {
174	if !p.HasMorePages() {
175		return nil, fmt.Errorf("no more pages available")
176	}
177
178	params := *p.params
179	params.NextToken = p.nextToken
180
181	var limit *int32
182	if p.options.Limit > 0 {
183		limit = &p.options.Limit
184	}
185	params.MaxResults = limit
186
187	result, err := p.client.ListGroundStations(ctx, &params, optFns...)
188	if err != nil {
189		return nil, err
190	}
191	p.firstPage = false
192
193	prevToken := p.nextToken
194	p.nextToken = result.NextToken
195
196	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
197		p.nextToken = nil
198	}
199
200	return result, nil
201}
202