Skip to content

Commit b281cf1

Browse files
authored
Update examples and tutorials (#2139)
Motivation: We're going to tag beta.1 soon, so the examples and tutorials need to be updated to reflect this. Modifications: - Regenerate example code - Update example code to use new APIs - Update example manifests to use the as-yet-unreleased beta.1 tag of each dependency Result: Examples are up-to-date
1 parent 1f2e78b commit b281cf1

File tree

48 files changed

+2129
-1068
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2129
-1068
lines changed

Examples/echo/Package.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ let package = Package(
2121
name: "echo",
2222
platforms: [.macOS("15.0")],
2323
dependencies: [
24-
.package(url: "https://github.com/grpc/grpc-swift", exact: "2.0.0-alpha.1"),
25-
.package(url: "https://github.com/grpc/grpc-swift-protobuf", exact: "1.0.0-alpha.1"),
26-
.package(url: "https://github.com/grpc/grpc-swift-nio-transport", branch: "1.0.0-alpha.1"),
27-
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
24+
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.1"),
25+
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.1"),
26+
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", branch: "1.0.0-beta.1"),
27+
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
2828
],
2929
targets: [
3030
.executableTarget(

Examples/echo/Sources/Generated/echo.grpc.swift

+742-240
Large diffs are not rendered by default.

Examples/echo/Sources/Subcommands/Collect.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Collect: AsyncParsableCommand {
3030
let client = GRPCClient(
3131
transport: try .http2NIOPosix(
3232
target: self.arguments.target,
33-
config: .defaults(transportSecurity: .plaintext)
33+
transportSecurity: .plaintext
3434
)
3535
)
3636

@@ -39,7 +39,7 @@ struct Collect: AsyncParsableCommand {
3939
try await client.run()
4040
}
4141

42-
let echo = Echo_Echo_Client(wrapping: client)
42+
let echo = Echo_Echo.Client(wrapping: client)
4343

4444
for _ in 0 ..< self.arguments.repetitions {
4545
let message = try await echo.collect { writer in

Examples/echo/Sources/Subcommands/Expand.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Expand: AsyncParsableCommand {
3030
let client = GRPCClient(
3131
transport: try .http2NIOPosix(
3232
target: self.arguments.target,
33-
config: .defaults(transportSecurity: .plaintext)
33+
transportSecurity: .plaintext
3434
)
3535
)
3636

@@ -39,7 +39,7 @@ struct Expand: AsyncParsableCommand {
3939
try await client.run()
4040
}
4141

42-
let echo = Echo_Echo_Client(wrapping: client)
42+
let echo = Echo_Echo.Client(wrapping: client)
4343

4444
for _ in 0 ..< self.arguments.repetitions {
4545
let message = Echo_EchoRequest.with { $0.text = self.arguments.message }

Examples/echo/Sources/Subcommands/Get.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct Get: AsyncParsableCommand {
2828
let client = GRPCClient(
2929
transport: try .http2NIOPosix(
3030
target: self.arguments.target,
31-
config: .defaults(transportSecurity: .plaintext)
31+
transportSecurity: .plaintext
3232
)
3333
)
3434

@@ -37,7 +37,7 @@ struct Get: AsyncParsableCommand {
3737
try await client.run()
3838
}
3939

40-
let echo = Echo_Echo_Client(wrapping: client)
40+
let echo = Echo_Echo.Client(wrapping: client)
4141

4242
for _ in 0 ..< self.arguments.repetitions {
4343
let message = Echo_EchoRequest.with { $0.text = self.arguments.message }

Examples/echo/Sources/Subcommands/Serve.swift

+20-24
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct Serve: AsyncParsableCommand {
2828
let server = GRPCServer(
2929
transport: .http2NIOPosix(
3030
address: .ipv4(host: "127.0.0.1", port: self.port),
31-
config: .defaults(transportSecurity: .plaintext)
31+
transportSecurity: .plaintext
3232
),
3333
services: [EchoService()]
3434
)
@@ -42,44 +42,40 @@ struct Serve: AsyncParsableCommand {
4242
}
4343
}
4444

45-
struct EchoService: Echo_Echo_ServiceProtocol {
45+
struct EchoService: Echo_Echo.SimpleServiceProtocol {
4646
func get(
47-
request: ServerRequest<Echo_EchoRequest>,
47+
request: Echo_EchoRequest,
4848
context: ServerContext
49-
) async throws -> ServerResponse<Echo_EchoResponse> {
50-
return ServerResponse(message: .with { $0.text = request.message.text })
49+
) async throws -> Echo_EchoResponse {
50+
return .with { $0.text = request.text }
5151
}
5252

5353
func collect(
54-
request: StreamingServerRequest<Echo_EchoRequest>,
54+
request: RPCAsyncSequence<Echo_EchoRequest, any Error>,
5555
context: ServerContext
56-
) async throws -> ServerResponse<Echo_EchoResponse> {
57-
let messages = try await request.messages.reduce(into: []) { $0.append($1.text) }
56+
) async throws -> Echo_EchoResponse {
57+
let messages = try await request.reduce(into: []) { $0.append($1.text) }
5858
let joined = messages.joined(separator: " ")
59-
return ServerResponse(message: .with { $0.text = joined })
59+
return .with { $0.text = joined }
6060
}
6161

6262
func expand(
63-
request: ServerRequest<Echo_EchoRequest>,
63+
request: Echo_EchoRequest,
64+
response: RPCWriter<Echo_EchoResponse>,
6465
context: ServerContext
65-
) async throws -> StreamingServerResponse<Echo_EchoResponse> {
66-
return StreamingServerResponse { writer in
67-
let parts = request.message.text.split(separator: " ")
68-
let messages = parts.map { part in Echo_EchoResponse.with { $0.text = String(part) } }
69-
try await writer.write(contentsOf: messages)
70-
return [:]
71-
}
66+
) async throws {
67+
let parts = request.text.split(separator: " ")
68+
let messages = parts.map { part in Echo_EchoResponse.with { $0.text = String(part) } }
69+
try await response.write(contentsOf: messages)
7270
}
7371

7472
func update(
75-
request: StreamingServerRequest<Echo_EchoRequest>,
73+
request: RPCAsyncSequence<Echo_EchoRequest, any Error>,
74+
response: RPCWriter<Echo_EchoResponse>,
7675
context: ServerContext
77-
) async throws -> StreamingServerResponse<Echo_EchoResponse> {
78-
return StreamingServerResponse { writer in
79-
for try await message in request.messages {
80-
try await writer.write(.with { $0.text = message.text })
81-
}
82-
return [:]
76+
) async throws {
77+
for try await message in request {
78+
try await response.write(.with { $0.text = message.text })
8379
}
8480
}
8581
}

Examples/echo/Sources/Subcommands/Update.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Update: AsyncParsableCommand {
3030
let client = GRPCClient(
3131
transport: try .http2NIOPosix(
3232
target: self.arguments.target,
33-
config: .defaults(transportSecurity: .plaintext)
33+
transportSecurity: .plaintext
3434
)
3535
)
3636

@@ -39,7 +39,7 @@ struct Update: AsyncParsableCommand {
3939
try await client.run()
4040
}
4141

42-
let echo = Echo_Echo_Client(wrapping: client)
42+
let echo = Echo_Echo.Client(wrapping: client)
4343

4444
for _ in 0 ..< self.arguments.repetitions {
4545
try await echo.update { writer in

Examples/hello-world/Package.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ let package = Package(
2121
name: "hello-world",
2222
platforms: [.macOS("15.0")],
2323
dependencies: [
24-
.package(url: "https://github.com/grpc/grpc-swift", exact: "2.0.0-alpha.1"),
25-
.package(url: "https://github.com/grpc/grpc-swift-protobuf", exact: "1.0.0-alpha.1"),
26-
.package(url: "https://github.com/grpc/grpc-swift-nio-transport", exact: "1.0.0-alpha.1"),
27-
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
24+
.package(url: "https://github.com/grpc/grpc-swift.git", exact: "2.0.0-beta.1"),
25+
.package(url: "https://github.com/grpc/grpc-swift-protobuf.git", exact: "1.0.0-beta.1"),
26+
.package(url: "https://github.com/grpc/grpc-swift-nio-transport.git", exact: "1.0.0-beta.1"),
27+
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
2828
],
2929
targets: [
3030
.executableTarget(

0 commit comments

Comments
 (0)