Skip to content

Commit 95717d1

Browse files
committed
add client side pagination to lazily fetch pages
1 parent f900646 commit 95717d1

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

aws/aws.go

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

babashka/babashka.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Namespace struct {
2222

2323
type Var struct {
2424
Name string "name"
25+
Code string `bencode:"code,omitempty"`
2526
}
2627

2728
type DescribeResponse struct {

gen/generate.clj

+21-2
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,24 @@
165165
(str prefix-fn-name "Output")
166166
(str aws-fn-name "Output")))
167167

168+
(def quoted-get-paginator
169+
(quote
170+
(defn get-paginator
171+
"Returns a fn that lazily fetches the pages for a given aws fn"
172+
[page-fn]
173+
(fn get-pages
174+
[input]
175+
(lazy-seq
176+
(let [page (page-fn input)]
177+
(if-let [next-continuation-token (:NextContinuationToken page)]
178+
(cons page (get-pages (assoc input :ContinuationToken next-continuation-token)))
179+
[page])))))))
180+
168181
(def t
169182
"
170183
// Code generated by generate.clj DO NOT EDIT
171184
package aws
172185
173-
174186
import (
175187
\"encoding/json\"
176188
\"github.com/aws/aws-sdk-go/aws/session\"
@@ -186,6 +198,12 @@ if message.Op == \"describe\" {
186198
response := &babashka.DescribeResponse{
187199
Format: \"json\",
188200
Namespaces: []babashka.Namespace{
201+
{Name: \"pod.tzzh.paginator\",
202+
Vars: []babashka.Var{
203+
{Name: \"get-paginator\",
204+
Code: `<%= paginator %>`},
205+
},
206+
},
189207
<% (doseq [[ns-name ns-fns] namespaces]
190208
%>{Name: \"pod.tzzh.<%= ns-name %>\",
191209
Vars: []babashka.Var{
@@ -236,7 +254,8 @@ if message.Op == \"describe\" {
236254

237255
(when (= *file* (System/getProperty "babashka.file"))
238256
(let [aws-go "./aws/aws.go"]
239-
(spit aws-go (template/eval t {:namespaces aws-api}))
257+
(spit aws-go (template/eval t {:namespaces aws-api
258+
:paginator (str quoted-get-paginator)}))
240259
(let [{:keys [err exit]} (shell/sh "go" "fmt" aws-go)]
241260
(when-not (empty? err)
242261
(print err))

0 commit comments

Comments
 (0)