Skip to content

Commit fa16c9f

Browse files
Add auto-pagination example. (#12)
## What changes are proposed in this pull request? That PR extends the Jobs V2 Client with example wrapper method that automatically paginates on to of a standard List API method. This is purely meant as an example for code generation. The PR also adds an option to pass the host when creating the client. ## How is this tested? No test.
1 parent c8de8a7 commit fa16c9f

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎databricks/internal/internal.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
type ClientOptions struct {
13+
Host string
1314
HTTPClient *http.Client
1415
Credentials auth.Credentials
1516
Timeout time.Duration

‎databricks/options/options.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import (
1212
// ClientOption is an option to configure Databricks API clients.
1313
type ClientOption func(*internal.ClientOptions) error
1414

15+
// WithHost returns a ClientOption to set the host for the client.
16+
func WithHost(h string) ClientOption {
17+
return func(o *internal.ClientOptions) error {
18+
o.Host = h
19+
return nil
20+
}
21+
}
22+
1523
// WithHTTPClient returns a ClientOption to use a specific HTTP Client when
1624
// making HTTP requests.
1725
//

‎databricks/options/unstable/unstable.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// ResolvedOptions contains the resolved configuration values from ClientOptions.
1818
type ResolvedOptions struct {
1919
Logger *slog.Logger
20+
Host string
2021
}
2122

2223
// Resolve applies all ClientOptions and returns the resolved configuration.

‎jobs/v2/jobs.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func NewClient(ctx context.Context, opts ...options.ClientOption) (*Client, erro
3434
return &Client{
3535
httpClient: httpClient,
3636
logger: resolved.Logger,
37+
host: resolved.Host,
3738
}, nil
3839
}
3940

@@ -82,18 +83,18 @@ func (c *Client) CreateJob(ctx context.Context, req *CreateJobRequest, opts ...a
8283
return resp, nil
8384
}
8485

85-
func ListJobs(ctx context.Context, req *ListJobsRequest, opts ...api.Option) (*ListJobsResponse, error) {
86+
func (c *Client) ListJobs(ctx context.Context, req *ListJobsRequest, opts ...api.Option) (*ListJobsResponse, error) {
8687
return nil, nil
8788
}
8889

89-
func ListJobsIter(ctx context.Context, req *ListJobsRequest, opts ...api.Option) iter.Seq2[*Job, error] {
90+
func (c *Client) ListJobsIter(ctx context.Context, req *ListJobsRequest, opts ...api.Option) iter.Seq2[*Job, error] {
9091
return func(yield func(*Job, error) bool) {
9192
pageReq := &ListJobsRequest{
9293
PageSize: req.PageSize,
9394
PageToken: req.PageToken,
9495
}
9596
for {
96-
resp, err := ListJobs(ctx, pageReq, opts...)
97+
resp, err := c.ListJobs(ctx, pageReq, opts...)
9798
if err != nil {
9899
yield(nil, err)
99100
return

0 commit comments

Comments
 (0)