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

Document the new service builder #2021

Merged
merged 26 commits into from
Dec 1, 2022
Merged
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e6e7a2f
Document the new service builder
82marbag Nov 22, 2022
3dfc04b
Generate docs for current service
82marbag Nov 22, 2022
79dc931
Address comments
82marbag Nov 23, 2022
ddbedf1
Rename variable
82marbag Nov 23, 2022
630a914
Merge branch 'main' into new-service-builder-docs
82marbag Nov 23, 2022
f7a2393
Change handler names
82marbag Nov 23, 2022
7a13a5f
Update docs
82marbag Nov 24, 2022
28cfe35
Update docs
82marbag Nov 24, 2022
c6e321d
Update docs
Nov 24, 2022
bb75fde
Update docs
82marbag Nov 24, 2022
58292cc
Merge branch 'main' into new-service-builder-docs
82marbag Nov 24, 2022
2260908
Update dependencies
82marbag Nov 24, 2022
566d12a
Update docs
82marbag Nov 25, 2022
0a943c6
Update docs
82marbag Nov 25, 2022
f687d5d
Address comments
82marbag Nov 29, 2022
78cc474
Address comments
82marbag Nov 30, 2022
28f182f
Fix CI
82marbag Nov 30, 2022
9e3bf62
Fix CI
82marbag Nov 30, 2022
bc9e5bd
Fix CI
82marbag Nov 30, 2022
8faff7d
Fix CI
82marbag Nov 30, 2022
9ec3ad3
Address comments
82marbag Nov 30, 2022
f2f83df
Update codegen-server/src/main/kotlin/software/amazon/smithy/rust/cod…
82marbag Nov 30, 2022
90fca46
Update codegen-server/src/main/kotlin/software/amazon/smithy/rust/cod…
82marbag Nov 30, 2022
43b45dd
Update codegen-server/src/main/kotlin/software/amazon/smithy/rust/cod…
82marbag Nov 30, 2022
be9335b
Update codegen-server/src/main/kotlin/software/amazon/smithy/rust/cod…
82marbag Nov 30, 2022
9d63316
Merge branch 'main' into new-service-builder-docs
LukeMathWalker Dec 1, 2022
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 @@ -319,8 +319,68 @@ class ServerServiceGeneratorV2(
private fun serviceStruct(): Writable = writable {
documentShape(service, model)

val functionSignatures =
82marbag marked this conversation as resolved.
Show resolved Hide resolved
operations.joinToString("\n") { "/// async fn ${builderFieldNames[it]}(input: input::${it.input.get().name}) -> Result<output::${it.output.get().name}, error::${it.id.name}Error> { todo!() }" }

rustTemplate(
"""
/// The [`$builderName`] is the place where you can register
/// your service $serviceName's operation implementations.
jjant marked this conversation as resolved.
Show resolved Hide resolved
///
/// Use [`$builderName`] to construct the
/// `$serviceName`. For each of the [operations] modeled in
/// your Smithy service, you need to provide an implementation in the
/// form of an async function that takes in the
/// operation's input as their first parameter, and returns the
/// operation's output. If your operation is fallible (i.e. it
/// contains the `errors` member in your Smithy model), the function
/// implementing the operation has to be fallible (i.e. return a
/// [`Result`]). **You must register an implementation for all
/// operations with the correct signature**, or your application
/// will fail to compile.
82marbag marked this conversation as resolved.
Show resolved Hide resolved
///
/// [`$serviceName`] can be converted into a type that implements [`tower::make::MakeService`], a _service
/// factory_, calling [`$serviceName::into_make_service`]. You can feed this value to a [Hyper server], and the
/// server will instantiate and [`serve`] your service.
///
/// [`$serviceName::into_make_service_with_connect_info`] converts $serviceName into [`tower::make::MakeService`]
/// with [`ConnectInfo`](#{SmithyHttpServer}::request::connect_info::ConnectInfo).
/// You can write your implementations to be passed in the connection information, populated by the [Hyper server].
///
/// Here's a full example to get you started:
///
/// ```rust
/// use std::net::SocketAddr;
/// use pokemon_service_server_sdk::{input, output, error};
///
/// ##[tokio::main]
/// pub async fn main() {
/// let app = $serviceName::builder_without_plugins()
${builderFieldNames.values.joinToString("\n") { "/// .$it($it)" }}
/// .build()
/// .expect("failed to build an instance of $serviceName");
///
/// let bind: SocketAddr = format!("{}:{}", "127.0.0.1", "6969")
82marbag marked this conversation as resolved.
Show resolved Hide resolved
/// .parse()
/// .expect("unable to parse the server bind address and port");
///
/// let server = hyper::Server::bind(&bind).serve(app.into_make_service());
///
/// // Run your service!
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
/// // if let Err(err) = server.await {
/// // eprintln!("server error: {}", err);
/// // }
/// }
///
$functionSignatures
///
/// ```
///
/// [`serve`]: https://docs.rs/hyper/0.14.16/hyper/server/struct.Builder.html##method.serve
/// [`tower::make::MakeService`]: https://docs.rs/tower/latest/tower/make/trait.MakeService.html
/// [HTTP binding traits]: https://awslabs.github.io/smithy/1.0/spec/core/http-traits.html
/// [operations]: https://awslabs.github.io/smithy/1.0/spec/core/model.html##operation
/// [Hyper server]: https://docs.rs/hyper/latest/hyper/server/index.html
##[derive(Clone)]
pub struct $serviceName<S = #{SmithyHttpServer}::routing::Route> {
router: #{SmithyHttpServer}::routers::RoutingService<#{Router}<S>, #{Protocol}>,
Expand Down