Skip to content

Commit 5fa3a23

Browse files
committed
Simplify lambda handler
1 parent f350f52 commit 5fa3a23

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

lucky_numbers/src/main.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ struct OutputPayload {
2525
numbers: Vec<u8>,
2626
}
2727

28-
fn get_name_or_default(name: &str) -> &str {
29-
if name.trim().is_empty() {
30-
"Anonymous"
31-
} else {
32-
name
33-
}
34-
}
35-
3628
/// This is where most of the work of our Rust lambda is done. Once an incoming request arrives
3729
/// at our lambda, this function will be invoked along with the request payload we have defined
3830
/// earlier. It expects a LambdaResponse containing our response payload. In this example,
@@ -42,13 +34,13 @@ fn lambda_handler(
4234
_c: Context,
4335
) -> Result<LambdaResponse, HandlerError> {
4436
let payload = e.body();
45-
let name = get_name_or_default(&payload.name);
37+
let name = &payload.name.to_uppercase();
4638
let count = std::cmp::min(std::cmp::max(2, payload.count), 20);
4739

4840
let response = LambdaResponseBuilder::new()
4941
.with_status(200)
5042
.with_json(OutputPayload {
51-
message: format!("Hi, {}. Your lucky numbers are:", name),
43+
message: format!("Hi, '{}'. Your lucky numbers are:", name),
5244
numbers: (1..=count).map(|_| thread_rng().gen_range(1, 42)).collect(),
5345
})
5446
.build();

0 commit comments

Comments
 (0)