Schafkopf-Server/Sources/App/Management/Configuration.swift
2022-10-12 19:32:03 +02:00

58 lines
1.1 KiB
Swift

import Foundation
struct Configuration {
let serverPort: Int
let mail: EMail
struct EMail {
/// The url to the root of the server
let serverDomain: String
/// SMTP server address
let emailHostname: String
/// username to login
let email: String
/// password to login
let password: String
/// The number of minutes until a password reset token is no longer valid
let tokenExpiryDuration: 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.EMail: Codable {
}
extension Configuration: Codable {
}