github.com/uber/kraken@v0.1.4/lib/backend/options.go (about) 1 // Copyright (c) 2016-2019 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package backend 15 16 // ListOptions defines the options which can be specified 17 // when listing names. It is used to enable pagination in list requests. 18 type ListOptions struct { 19 Paginated bool 20 MaxKeys int 21 ContinuationToken string 22 } 23 24 // DefaultListOptions defines the defaults for list operations. 25 func DefaultListOptions() *ListOptions { 26 return &ListOptions{ 27 Paginated: false, 28 MaxKeys: DefaultListMaxKeys, 29 ContinuationToken: "", 30 } 31 } 32 33 // ListOption is used to configure list calls via variadic functional options. 34 type ListOption func(*ListOptions) 35 36 // ListWithPagination configures the list command to use pagination. 37 func ListWithPagination() ListOption { 38 return func(opt *ListOptions) { 39 opt.Paginated = true 40 } 41 } 42 43 // ListWithMaxKeys configures the list command to return a max 44 // number of keys if pagination is enabled. 45 func ListWithMaxKeys(max int) ListOption { 46 return func(opt *ListOptions) { 47 opt.MaxKeys = max 48 } 49 } 50 51 // ListWithContinuationToken configures the list command return 52 // results starting at the continuation token if pagination is enabled. 53 func ListWithContinuationToken(token string) ListOption { 54 return func(opt *ListOptions) { 55 opt.ContinuationToken = token 56 } 57 }