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 all active game sessions that match a set of search criteria and sorts 16// them into a specified order. When searching for game sessions, you specify 17// exactly where you want to search and provide a search filter expression, a sort 18// expression, or both. A search request can search only one fleet, but it can 19// search all of a fleet's locations. This operation can be used in the following 20// ways: 21// 22// * To search all game sessions that are currently running on all locations 23// in a fleet, provide a fleet or alias ID. This approach returns game sessions in 24// the fleet's home Region and all remote locations that fit the search 25// criteria. 26// 27// * To search all game sessions that are currently running on a 28// specific fleet location, provide a fleet or alias ID and a location name. For 29// location, you can specify a fleet's home Region or any remote location. 30// 31// Use the 32// pagination parameters to retrieve results as a set of sequential pages. If 33// successful, a GameSession object is returned for each game session that matches 34// the request. Search finds game sessions that are in ACTIVE status only. To 35// retrieve information on game sessions in other statuses, use 36// DescribeGameSessions. You can search or sort by the following game session 37// attributes: 38// 39// * gameSessionId -- A unique identifier for the game session. You 40// can use either a GameSessionId or GameSessionArn value. 41// 42// * gameSessionName -- 43// Name assigned to a game session. This value is set when requesting a new game 44// session with CreateGameSession or updating with UpdateGameSession. Game session 45// names do not need to be unique to a game session. 46// 47// * gameSessionProperties -- 48// Custom data defined in a game session's GameProperty parameter. GameProperty 49// values are stored as key:value pairs; the filter expression must indicate the 50// key and a string to search the data values for. For example, to search for game 51// sessions with custom data containing the key:value pair "gameMode:brawl", 52// specify the following: gameSessionProperties.gameMode = "brawl". All custom data 53// values are searched as strings. 54// 55// * maximumSessions -- Maximum number of player 56// sessions allowed for a game session. This value is set when requesting a new 57// game session with CreateGameSession or updating with UpdateGameSession. 58// 59// * 60// creationTimeMillis -- Value indicating when a game session was created. It is 61// expressed in Unix time as milliseconds. 62// 63// * playerSessionCount -- Number of 64// players currently connected to a game session. This value changes rapidly as 65// players join the session or drop out. 66// 67// * hasAvailablePlayerSessions -- Boolean 68// value indicating whether a game session has reached its maximum number of 69// players. It is highly recommended that all search requests include this filter 70// attribute to optimize search performance and return only sessions that players 71// can join. 72// 73// Returned values for playerSessionCount and hasAvailablePlayerSessions 74// change quickly as players join sessions and others drop out. Results should be 75// considered a snapshot in time. Be sure to refresh search results often, and 76// handle sessions that fill up before a player can join. Related actions 77// CreateGameSession | DescribeGameSessions | DescribeGameSessionDetails | 78// SearchGameSessions | UpdateGameSession | GetGameSessionLogUrl | 79// StartGameSessionPlacement | DescribeGameSessionPlacement | 80// StopGameSessionPlacement | All APIs by task 81// (https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets) 82func (c *Client) SearchGameSessions(ctx context.Context, params *SearchGameSessionsInput, optFns ...func(*Options)) (*SearchGameSessionsOutput, error) { 83 if params == nil { 84 params = &SearchGameSessionsInput{} 85 } 86 87 result, metadata, err := c.invokeOperation(ctx, "SearchGameSessions", params, optFns, addOperationSearchGameSessionsMiddlewares) 88 if err != nil { 89 return nil, err 90 } 91 92 out := result.(*SearchGameSessionsOutput) 93 out.ResultMetadata = metadata 94 return out, nil 95} 96 97// Represents the input for a request operation. 98type SearchGameSessionsInput struct { 99 100 // A unique identifier for the alias associated with the fleet to search for active 101 // game sessions. You can use either the alias ID or ARN value. Each request must 102 // reference either a fleet ID or alias ID, but not both. 103 AliasId *string 104 105 // String containing the search criteria for the session search. If no filter 106 // expression is included, the request returns results for all game sessions in the 107 // fleet that are in ACTIVE status. A filter expression can contain one or multiple 108 // conditions. Each condition consists of the following: 109 // 110 // * Operand -- Name of a 111 // game session attribute. Valid values are gameSessionName, gameSessionId, 112 // gameSessionProperties, maximumSessions, creationTimeMillis, playerSessionCount, 113 // hasAvailablePlayerSessions. 114 // 115 // * Comparator -- Valid comparators are: =, <>, <, >, 116 // <=, >=. 117 // 118 // * Value -- Value to be searched for. Values may be numbers, boolean 119 // values (true/false) or strings depending on the operand. String values are case 120 // sensitive and must be enclosed in single quotes. Special characters must be 121 // escaped. Boolean and string values can only be used with the comparators = and 122 // <>. For example, the following filter expression searches on gameSessionName: 123 // "FilterExpression": "gameSessionName = 'Matt\\'s Awesome Game 1'". 124 // 125 // To chain 126 // multiple conditions in a single expression, use the logical keywords AND, OR, 127 // and NOT and parentheses as needed. For example: x AND y AND NOT z, NOT (x OR y). 128 // Session search evaluates conditions from left to right using the following 129 // precedence rules: 130 // 131 // * =, <>, <, >, <=, >= 132 // 133 // * Parentheses 134 // 135 // * NOT 136 // 137 // * AND 138 // 139 // * OR 140 // 141 // For 142 // example, this filter expression retrieves game sessions hosting at least ten 143 // players that have an open player slot: "maximumSessions>=10 AND 144 // hasAvailablePlayerSessions=true". 145 FilterExpression *string 146 147 // A unique identifier for the fleet to search for active game sessions. You can 148 // use either the fleet ID or ARN value. Each request must reference either a fleet 149 // ID or alias ID, but not both. 150 FleetId *string 151 152 // The maximum number of results to return. Use this parameter with NextToken to 153 // get results as a set of sequential pages. The maximum number of results returned 154 // is 20, even if this value is not set or is set higher than 20. 155 Limit *int32 156 157 // A fleet location to search for game sessions. You can specify a fleet's home 158 // Region or a remote location. Use the AWS Region code format, such as us-west-2. 159 Location *string 160 161 // A token that indicates the start of the next sequential page of results. Use the 162 // token that is returned with a previous call to this operation. To start at the 163 // beginning of the result set, do not specify a value. 164 NextToken *string 165 166 // Instructions on how to sort the search results. If no sort expression is 167 // included, the request returns results in random order. A sort expression 168 // consists of the following elements: 169 // 170 // * Operand -- Name of a game session 171 // attribute. Valid values are gameSessionName, gameSessionId, 172 // gameSessionProperties, maximumSessions, creationTimeMillis, playerSessionCount, 173 // hasAvailablePlayerSessions. 174 // 175 // * Order -- Valid sort orders are ASC (ascending) 176 // and DESC (descending). 177 // 178 // For example, this sort expression returns the oldest 179 // active sessions first: "SortExpression": "creationTimeMillis ASC". Results with 180 // a null value for the sort operand are returned at the end of the list. 181 SortExpression *string 182} 183 184// Represents the returned data in response to a request operation. 185type SearchGameSessionsOutput struct { 186 187 // A collection of objects containing game session properties for each session that 188 // matches the request. 189 GameSessions []types.GameSession 190 191 // A token that indicates where to resume retrieving results on the next call to 192 // this operation. If no token is returned, these results represent the end of the 193 // list. 194 NextToken *string 195 196 // Metadata pertaining to the operation's result. 197 ResultMetadata middleware.Metadata 198} 199 200func addOperationSearchGameSessionsMiddlewares(stack *middleware.Stack, options Options) (err error) { 201 err = stack.Serialize.Add(&awsAwsjson11_serializeOpSearchGameSessions{}, middleware.After) 202 if err != nil { 203 return err 204 } 205 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpSearchGameSessions{}, middleware.After) 206 if err != nil { 207 return err 208 } 209 if err = addSetLoggerMiddleware(stack, options); err != nil { 210 return err 211 } 212 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 213 return err 214 } 215 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 216 return err 217 } 218 if err = addResolveEndpointMiddleware(stack, options); err != nil { 219 return err 220 } 221 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 222 return err 223 } 224 if err = addRetryMiddlewares(stack, options); err != nil { 225 return err 226 } 227 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 228 return err 229 } 230 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 231 return err 232 } 233 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 234 return err 235 } 236 if err = addClientUserAgent(stack); err != nil { 237 return err 238 } 239 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 240 return err 241 } 242 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 243 return err 244 } 245 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opSearchGameSessions(options.Region), middleware.Before); err != nil { 246 return err 247 } 248 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 249 return err 250 } 251 if err = addResponseErrorMiddleware(stack); err != nil { 252 return err 253 } 254 if err = addRequestResponseLogging(stack, options); err != nil { 255 return err 256 } 257 return nil 258} 259 260// SearchGameSessionsAPIClient is a client that implements the SearchGameSessions 261// operation. 262type SearchGameSessionsAPIClient interface { 263 SearchGameSessions(context.Context, *SearchGameSessionsInput, ...func(*Options)) (*SearchGameSessionsOutput, error) 264} 265 266var _ SearchGameSessionsAPIClient = (*Client)(nil) 267 268// SearchGameSessionsPaginatorOptions is the paginator options for 269// SearchGameSessions 270type SearchGameSessionsPaginatorOptions struct { 271 // The maximum number of results to return. Use this parameter with NextToken to 272 // get results as a set of sequential pages. The maximum number of results returned 273 // is 20, even if this value is not set or is set higher than 20. 274 Limit int32 275 276 // Set to true if pagination should stop if the service returns a pagination token 277 // that matches the most recent token provided to the service. 278 StopOnDuplicateToken bool 279} 280 281// SearchGameSessionsPaginator is a paginator for SearchGameSessions 282type SearchGameSessionsPaginator struct { 283 options SearchGameSessionsPaginatorOptions 284 client SearchGameSessionsAPIClient 285 params *SearchGameSessionsInput 286 nextToken *string 287 firstPage bool 288} 289 290// NewSearchGameSessionsPaginator returns a new SearchGameSessionsPaginator 291func NewSearchGameSessionsPaginator(client SearchGameSessionsAPIClient, params *SearchGameSessionsInput, optFns ...func(*SearchGameSessionsPaginatorOptions)) *SearchGameSessionsPaginator { 292 if params == nil { 293 params = &SearchGameSessionsInput{} 294 } 295 296 options := SearchGameSessionsPaginatorOptions{} 297 if params.Limit != nil { 298 options.Limit = *params.Limit 299 } 300 301 for _, fn := range optFns { 302 fn(&options) 303 } 304 305 return &SearchGameSessionsPaginator{ 306 options: options, 307 client: client, 308 params: params, 309 firstPage: true, 310 } 311} 312 313// HasMorePages returns a boolean indicating whether more pages are available 314func (p *SearchGameSessionsPaginator) HasMorePages() bool { 315 return p.firstPage || p.nextToken != nil 316} 317 318// NextPage retrieves the next SearchGameSessions page. 319func (p *SearchGameSessionsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*SearchGameSessionsOutput, error) { 320 if !p.HasMorePages() { 321 return nil, fmt.Errorf("no more pages available") 322 } 323 324 params := *p.params 325 params.NextToken = p.nextToken 326 327 var limit *int32 328 if p.options.Limit > 0 { 329 limit = &p.options.Limit 330 } 331 params.Limit = limit 332 333 result, err := p.client.SearchGameSessions(ctx, ¶ms, optFns...) 334 if err != nil { 335 return nil, err 336 } 337 p.firstPage = false 338 339 prevToken := p.nextToken 340 p.nextToken = result.NextToken 341 342 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 343 p.nextToken = nil 344 } 345 346 return result, nil 347} 348 349func newServiceMetadataMiddleware_opSearchGameSessions(region string) *awsmiddleware.RegisterServiceMetadata { 350 return &awsmiddleware.RegisterServiceMetadata{ 351 Region: region, 352 ServiceID: ServiceID, 353 SigningName: "gamelift", 354 OperationName: "SearchGameSessions", 355 } 356} 357