Last active
April 10, 2019 08:18
-
-
Save samdods/79f36b685f4a36d0c77a63a176b0c10a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Frank { | |
static func start(port: Int = 8080) { | |
// ... steps 1 to 8 from sample code above ... | |
} | |
} | |
typealias ResponseBodyProvider = () -> String | |
private var routedGET: [String: ResponseBodyProvider] = [:] | |
func get(_ path: String, bodyProvider: @escaping ResponseBodyProvider) { | |
routedGET[path] = bodyProvider | |
} | |
private func routeRequest(_ request: Request) throws -> String? { | |
guard let bodyProvider = routedGET[request.path] else { | |
throw NoRouteError() // hypothetical error | |
} | |
return bodyProvider() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment