Skip to content

Commit 352fbe8

Browse files
committed
Update APIs and comments for SCF
1 parent 56827ea commit 352fbe8

File tree

37 files changed

+642
-647
lines changed

37 files changed

+642
-647
lines changed

Examples/CloudFunctions/Sources/APIGateway/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ import TencentSCFRuntime
3131

3232
// MARK: - Run SCF function
3333

34-
Lambda.run(APIGatewayProxyLambda())
34+
SCF.run(APIGatewayProxySCF())
3535

3636
// MARK: - Handler, Request and Response
3737

3838
// FIXME: Use proper Event abstractions once added to TencentSCFRuntime
39-
struct APIGatewayProxyLambda: EventLoopLambdaHandler {
39+
struct APIGatewayProxySCF: EventLoopSCFHandler {
4040
public typealias In = APIGateway.Request
4141
public typealias Out = APIGateway.Response
4242

43-
public func handle(context: Lambda.Context, event: APIGateway.Request) -> EventLoopFuture<APIGateway.Response> {
43+
public func handle(context: SCF.Context, event: APIGateway.Request) -> EventLoopFuture<APIGateway.Response> {
4444
context.logger.debug("hello, api gateway!")
45-
return context.eventLoop.makeSucceededFuture(APIGateway.Response(statusCode: .ok, body: "hello, world!"))
45+
return context.eventLoop.makeSucceededFuture(APIGateway.Response(statusCode: .ok, body: "Hello, world!"))
4646
}
4747
}

Examples/CloudFunctions/Sources/Benchmark/main.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@
2828
import NIO
2929
import TencentSCFRuntimeCore
3030

31-
// If you would like to benchmark Swift's SCF Runtime,
32-
// use this example which is more performant.
33-
// `EventLoopLambdaHandler` does not offload the cloud function processing to a separate thread
31+
// If you would like to benchmark Swift's SCF Runtime, use this example which is more performant.
32+
// `EventLoopSCFHandler` does not offload the cloud function processing to a separate thread
3433
// while the Closure-based handlers do.
35-
Lambda.run(BenchmarkHandler())
34+
SCF.run(BenchmarkHandler())
3635

37-
struct BenchmarkHandler: EventLoopLambdaHandler {
36+
struct BenchmarkHandler: EventLoopSCFHandler {
3837
typealias In = String
3938
typealias Out = String
4039

41-
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
42-
context.eventLoop.makeSucceededFuture("hello, world!")
40+
func handle(context: SCF.Context, event: String) -> EventLoopFuture<String> {
41+
context.eventLoop.makeSucceededFuture("Hello, world!")
4342
}
4443
}

Examples/CloudFunctions/Sources/CurrencyExchange/main.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ import FoundationXML
3434
#endif
3535
import Logging
3636

37-
// MARK: - Run Lambda
37+
// MARK: - Run SCF function
3838

39-
Lambda.run { (context: Lambda.Context, _: Request, callback: @escaping (Result<[Exchange], Error>) -> Void) in
39+
SCF.run { (context: SCF.Context, _: Request, callback: @escaping (Result<[Exchange], Error>) -> Void) in
4040
let calculator = ExchangeRatesCalculator()
4141
calculator.run(logger: context.logger, callback: callback)
4242
}
4343

4444
// MARK: - Business Logic
4545

46-
// This is a contrived example performing currency exchange rate lookup and conversion using URLSession and XML parsing
46+
// This is a contrived example performing currency exchange rate lookup and conversion using
47+
// URLSession and XML parsing.
4748
struct ExchangeRatesCalculator {
4849
static let currencies = ["EUR", "USD", "JPY"]
4950
static let currenciesEmojies = [
@@ -56,7 +57,8 @@ struct ExchangeRatesCalculator {
5657
let calendar: Calendar
5758

5859
init() {
59-
// This is data from HMRC, the UK tax authority. Therefore we want to use their locale when interpreting data from the server.
60+
// This is data from HMRC, the UK tax authority. Therefore we want to use their
61+
// locale when interpreting data from the server.
6062
self.locale = Locale(identifier: "en_GB")
6163
// Use the UK calendar, not the system one.
6264
var calendar = self.locale.calendar

Examples/CloudFunctions/Sources/ErrorHandling/main.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ import TencentSCFRuntime
2929

3030
// MARK: - Run SCF function
3131

32-
// switch over the error type "requested" by the request, and trigger such error accordingly
33-
Lambda.run { (context: Lambda.Context, request: Request, callback: (Result<Response, Error>) -> Void) in
32+
// Switch over the error type "requested" by the request, and trigger such error accordingly.
33+
SCF.run { (context: SCF.Context, request: Request, callback: (Result<Response, Error>) -> Void) in
3434
switch request.error {
35-
// no error here!
35+
// No error here!
3636
case .none:
3737
callback(.success(Response(scfRequestID: context.requestID, requestID: request.requestID, status: .ok)))
38-
// trigger a "managed" error - domain specific business logic failure
38+
// Trigger a "managed" error - domain specific business logic failure.
3939
case .managed:
4040
callback(.success(Response(scfRequestID: context.requestID, requestID: request.requestID, status: .error)))
41-
// trigger an "unmanaged" error - an unexpected Swift Error triggered while processing the request
41+
// Trigger an "unmanaged" error - an unexpected Swift Error triggered while processing the request.
4242
case .unmanaged(let error):
4343
callback(.failure(UnmanagedError(description: error)))
44-
// trigger a "fatal" error - a panic type error which will crash the process
44+
// Trigger a "fatal" error - a panic type error which will crash the process.
4545
case .fatal:
4646
fatalError("crash!")
4747
}

Examples/CloudFunctions/Sources/HelloWorld/main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import TencentSCFRuntime
2929

30-
// introductory example, the obligatory "hello, world!"
31-
Lambda.run { (_: Lambda.Context, _: String, callback: (Result<String, Error>) -> Void) in
32-
callback(.success("hello, world!"))
30+
// Introductory example, the obligatory "Hello, world!"
31+
SCF.run { (_: SCF.Context, _: String, callback: (Result<String, Error>) -> Void) in
32+
callback(.success("Hello, world!"))
3333
}

Examples/LocalDebugging/MyCloudFunction/Sources/MyCloudFunction/main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import Shared
2929
import TencentSCFRuntime
3030

31-
// set LOCAL_SCF_SERVER_ENABLED env variable to "true" to start
32-
// a local server simulator which will allow local debugging
33-
Lambda.run { (_, request: Request, callback: @escaping (Result<Response, Error>) -> Void) in
31+
// Set LOCAL_SCF_SERVER_ENABLED env variable to "true" to start a local server simulator
32+
// which will allow local debugging.
33+
SCF.run { (_, request: Request, callback: @escaping (Result<Response, Error>) -> Void) in
3434
// TODO: something useful
3535
callback(.success(Response(message: "Hello, \(request.name)!")))
3636
}

Sources/CodableSample/main.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ struct Response: Codable {
3636
let body: String
3737
}
3838

39-
// in this example we are receiving and responding with codables. Request and Response above are examples of how to use
40-
// codables to model your reqeuest and response objects
41-
struct Handler: EventLoopLambdaHandler {
39+
// In this example we are receiving and responding with codables. Request and Response
40+
// above are examples of how to use codables to model your reqeuest and response objects.
41+
struct Handler: EventLoopSCFHandler {
4242
typealias In = Request
4343
typealias Out = Response
4444

45-
func handle(context: Lambda.Context, event: Request) -> EventLoopFuture<Response> {
46-
// as an example, respond with the input event's reversed body
45+
func handle(context: SCF.Context, event: Request) -> EventLoopFuture<Response> {
46+
// As an example, respond with the input event's reversed body.
4747
context.eventLoop.makeSucceededFuture(Response(body: String(event.body.reversed())))
4848
}
4949
}
5050

51-
Lambda.run(Handler())
51+
SCF.run(Handler())
5252

5353
// MARK: - this can also be expressed as a closure:
5454

5555
/*
56-
Lambda.run { (_, request: Request, callback) in
57-
callback(.success(Response(body: String(request.body.reversed()))))
56+
SCF.run { (_, request: Request, callback) in
57+
callback(.success(Response(body: String(request.body.reversed()))))
5858
}
5959
*/

Sources/StringSample/main.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@
2828
import NIO
2929
import TencentSCFRuntimeCore
3030

31-
// in this example we are receiving and responding with strings
32-
struct Handler: EventLoopLambdaHandler {
31+
// In this example we are receiving and responding with strings.
32+
struct Handler: EventLoopSCFHandler {
3333
typealias In = String
3434
typealias Out = String
3535

36-
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<String> {
37-
// as an example, respond with the event's reversed body
36+
func handle(context: SCF.Context, event: String) -> EventLoopFuture<String> {
37+
// As an example, respond with the event's reversed body.
3838
context.eventLoop.makeSucceededFuture(String(event.reversed()))
3939
}
4040
}
4141

42-
Lambda.run(Handler())
42+
SCF.run(Handler())
4343

4444
// MARK: - this can also be expressed as a closure:
4545

4646
/*
47-
Lambda.run { (_, event: String, callback) in
48-
callback(.success(String(event.reversed())))
47+
SCF.run { (_, event: String, callback) in
48+
callback(.success(String(event.reversed())))
4949
}
5050
*/

Sources/TencentSCFEvents/APIGateway.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import struct Foundation.Data
1616

1717
// https://cloud.tencent.com/document/product/583/12513
1818

19+
/// `APIGateway.Request` contains data coming from the API Gateway.
1920
public enum APIGateway {
20-
/// APIGatewayRequest contains data coming from the API Gateway
2121
public struct Request: Codable {
2222
public struct Context: Codable {
2323
public let identity: [String: String]

Sources/TencentSCFEvents/TencentCloud/Region.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
//
1313
//===------------------------------------------------------------------------------------===//
1414

15-
// list all available regions using tccli:
15+
// List all available regions using tccli:
1616
// $ tccli cvm DescribeRegions
1717

18-
/// Enumeration of the Tencent Cloud regions and zones.
18+
/// Enumeration of the Tencent Cloud regions.
1919
public enum TencentCloud {
2020
public struct Region: RawRepresentable, CustomStringConvertible, Equatable, Hashable {
2121
public typealias RawValue = String

0 commit comments

Comments
 (0)