Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add client opts extension point for waiters/paginators #518

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

package software.amazon.smithy.go.codegen.integration;

import static java.util.Collections.emptySet;
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate;

import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
Expand All @@ -42,6 +46,10 @@
* Implements support for PaginatedTrait.
*/
public class Paginators implements GoIntegration {
public Set<Symbol> getAdditionalClientOptions() {
return emptySet();
}

@Override
public void writeAdditionalFiles(
GoSettings settings,
Expand Down Expand Up @@ -217,13 +225,21 @@ private void writePaginator(
}
});

var optFns = GoWriter.ChainWritable.of(
getAdditionalClientOptions().stream()
.map(it -> goTemplate("$T,", it))
.toList()
).compose(false);
writer.write("""
optFns = append([]func(*Options) {
$W
}, optFns...)
result, err := p.client.$L(ctx, &params, optFns...)
if err != nil {
return nil, err
}
p.firstPage = false
""", operationSymbol.getName());
""", optFns, operationSymbol.getName());

var outputMemberPath = paginationInfo.getOutputTokenMemberPath();
var tokenMember = outputMemberPath.get(outputMemberPath.size() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

package software.amazon.smithy.go.codegen.integration;

import static java.util.Collections.emptySet;
import static software.amazon.smithy.go.codegen.GoWriter.autoDocTemplate;
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate;

import java.util.Map;
import java.util.Optional;
import java.util.Set;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
Expand Down Expand Up @@ -53,6 +55,10 @@ public class Waiters implements GoIntegration {
private static final String WAITER_INVOKER_FUNCTION_NAME = "Wait";
private static final String WAITER_INVOKER_WITH_OUTPUT_FUNCTION_NAME = "WaitForOutput";

public Set<Symbol> getAdditionalClientOptions() {
return emptySet();
}

@Override
public void writeAdditionalFiles(
GoSettings settings,
Expand Down Expand Up @@ -440,10 +446,22 @@ private void generateWaiterInvokerWithOutput(
}).write("");

// make a request
var baseOpts = GoWriter.ChainWritable.of(
getAdditionalClientOptions().stream()
.map(it -> goTemplate("$T,", it))
.toList()
).compose(false);
writer.openBlock("out, err := w.client.$T(ctx, params, func (o *Options) { ", "})",
operationSymbol, () -> {
writer.write("""
baseOpts := []func(*Options) {
$W
}""", baseOpts);
writer.write("o.APIOptions = append(o.APIOptions, apiOptions...)");
writer.write("""
for _, opt := range baseOpts {
opt(o)
}
for _, opt := range options.ClientOptions {
opt(o)
}""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ software.amazon.smithy.go.codegen.integration.AddChecksumRequiredMiddleware
software.amazon.smithy.go.codegen.integration.RequiresLengthTraitSupport
software.amazon.smithy.go.codegen.integration.EndpointHostPrefixMiddleware
software.amazon.smithy.go.codegen.integration.OperationInterfaceGenerator
software.amazon.smithy.go.codegen.integration.Paginators
software.amazon.smithy.go.codegen.integration.Waiters
software.amazon.smithy.go.codegen.integration.ClientLogger
software.amazon.smithy.go.codegen.endpoints.EndpointClientPluginsGenerator

Expand Down
Loading