33 lines
672 B
Swift
33 lines
672 B
Swift
import Foundation
|
|
|
|
struct Configuration {
|
|
|
|
let serverPort: Int
|
|
}
|
|
|
|
extension Configuration {
|
|
|
|
init(loadFromUrl url: URL) throws {
|
|
let data: Data
|
|
do {
|
|
data = try Data(contentsOf: url)
|
|
} catch {
|
|
print("Failed to load configuration data from \(url.path): \(error)")
|
|
throw error
|
|
}
|
|
try self.init(data: data)
|
|
}
|
|
|
|
init(data: Data) throws {
|
|
do {
|
|
self = try JSONDecoder().decode(Configuration.self, from: data)
|
|
} catch {
|
|
print("Failed to decode configuration: \(error)")
|
|
throw error
|
|
}
|
|
}
|
|
}
|
|
extension Configuration: Codable {
|
|
|
|
}
|