From 733a4394a3a499b23a72db5e903bcf86349aed4b Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Date: Sat, 19 Oct 2024 12:37:33 -0300 Subject: [PATCH] swift flying fox added (#7859) --- swift/flying-fox/Package.swift | 30 ++++++++++++++++++++ swift/flying-fox/Sources/server/Server.swift | 23 +++++++++++++++ swift/flying-fox/config.yaml | 4 +++ 3 files changed, 57 insertions(+) create mode 100644 swift/flying-fox/Package.swift create mode 100644 swift/flying-fox/Sources/server/Server.swift create mode 100644 swift/flying-fox/config.yaml diff --git a/swift/flying-fox/Package.swift b/swift/flying-fox/Package.swift new file mode 100644 index 00000000000..de920c60d18 --- /dev/null +++ b/swift/flying-fox/Package.swift @@ -0,0 +1,30 @@ +// swift-tools-version:6.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "server", + platforms: [ + .macOS("10.15") + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + .package(url: "https://github.com/swhitty/FlyingFox.git", .upToNextMajor(from: "0.18.0")) + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .executableTarget( + name: "server", + dependencies: [ + .product(name: "FlyingFox", package: "FlyingFox") + ], + swiftSettings: [ + // Enable better optimizations when building in Release configuration. Despite the use of + // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release + // builds. See for details. + .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release)) + ]) + ] +) diff --git a/swift/flying-fox/Sources/server/Server.swift b/swift/flying-fox/Sources/server/Server.swift new file mode 100644 index 00000000000..67831734093 --- /dev/null +++ b/swift/flying-fox/Sources/server/Server.swift @@ -0,0 +1,23 @@ +import FlyingFox + +@main +struct Server { + static func main() async throws { + let server = HTTPServer(port: 3000) + + await server.appendRoute("GET /") { _ in + return HTTPResponse(statusCode: .ok) + } + + await server.appendRoute("GET /user/:id") { request in + let user = request.routeParameters["id"] ?? "" + return HTTPResponse(statusCode: .ok, body: user.data(using: .utf8)!) + } + + await server.appendRoute("POST /user") { _ in + return HTTPResponse(statusCode: .ok) + } + + try await server.start() + } +} diff --git a/swift/flying-fox/config.yaml b/swift/flying-fox/config.yaml new file mode 100644 index 00000000000..c19901da2ae --- /dev/null +++ b/swift/flying-fox/config.yaml @@ -0,0 +1,4 @@ +framework: + github: swhitty/FlyingFox + version: 0.18.0 + name: flying-fox