Skip to content

Commit

Permalink
feat: add client config passthrough to waiter opts (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws authored Feb 15, 2024
1 parent 04af2e5 commit d43f947
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,21 @@ public static Writable goDocTemplate(String contents) {
* @return writer for formatted docs.
*/
public static Writable autoDocTemplate(String contents) {
return GoWriter.ChainWritable.of(
Arrays.stream(contents.split("\n\n"))
.map(it -> docParagraphWriter(it.replace("\n", " ")))
.toList()
).compose(false);
var paragraphs = contents.split("\n\n");
var chain = new GoWriter.ChainWritable();
for (int i = 0; i < paragraphs.length; ++i) {
chain.add(docParagraphWriter(paragraphs[i], i < paragraphs.length - 1));
}
return chain.compose(false);
}

private static GoWriter.Writable docParagraphWriter(String paragraph) {
return writer -> writer.writeDocs(paragraph).writeDocs("");
private static GoWriter.Writable docParagraphWriter(String paragraph, boolean writeNewline) {
return writer -> {
writer.writeDocs(paragraph);
if (writeNewline) {
writer.writeDocs("");
}
};
}

@SafeVarargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@

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

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 software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.go.codegen.ClientOptions;
import software.amazon.smithy.go.codegen.GoDelegator;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.GoWriter;
Expand Down Expand Up @@ -139,15 +143,31 @@ private void generateWaiterOptions(
writer.addUseImports(SmithyGoDependency.TIME);

writer.write("");
writer.writeDocs(
"Set of options to modify how an operation is invoked. These apply to all operations "
+ "invoked for this client. Use functional options on operation call to modify "
+ "this list for per operation behavior."
);
var apiOptionsDocs = autoDocTemplate("""
Set of options to modify how an operation is invoked. These apply to all operations invoked
for this client. Use functional options on operation call to modify this list for per
operation behavior.
Passing options here is functionally equivalent to passing values to this config's
ClientOptions field that extend the inner client's APIOptions directly.""");
Symbol stackSymbol = SymbolUtils.createPointableSymbolBuilder("Stack",
SmithyGoDependency.SMITHY_MIDDLEWARE)
.build();
writer.write("APIOptions []func($P) error", stackSymbol);
writer.write(goTemplate("""
$W
APIOptions []func($P) error
""", apiOptionsDocs, stackSymbol));

var clientOptionsDocs = autoDocTemplate("""
Functional options to be passed to all operations invoked by this client.
Function values that modify the inner APIOptions are applied after the waiter config's own
APIOptions modifiers.""");
writer.write("");
writer.write(goTemplate("""
$W
ClientOptions []func(*$L)
""", clientOptionsDocs, ClientOptions.NAME));

writer.write("");
writer.writeDocs(
Expand Down Expand Up @@ -423,6 +443,10 @@ private void generateWaiterInvokerWithOutput(
writer.openBlock("out, err := w.client.$T(ctx, params, func (o *Options) { ", "})",
operationSymbol, () -> {
writer.write("o.APIOptions = append(o.APIOptions, apiOptions...)");
writer.write("""
for _, opt := range options.ClientOptions {
opt(o)
}""");
});
writer.write("");

Expand Down

0 comments on commit d43f947

Please sign in to comment.