Configuration

public struct Configuration : Codable

This struct represents the configuration of an application

Example usage:

// path represents a json file location that have the same key names as the struct props
let file = File(path)
if file.exists == false {
    print("Configuration file doesn't exist!")
}
do {
    try file.open(.read, permissions: .readUser)
    defer { file.close() }
    let json = try file.readString()
    let conf = try Configuration(json)
    app.config = conf // assign it to your application's config to be used when you launch the server
} catch {
    print(error)
}
  • db

    database configuration including host, user, pass,…

    Declaration

    Swift

    public let db: DBConfiguration?
  • init configuration with Data

    Declaration

    Swift

    public init(data: Data) throws
  • init configuration with JSON

    Declaration

    Swift

    public init(_ json: String, using encoding: String.Encoding = .utf8) throws
  • init configuration from a URL

    Declaration

    Swift

    public init(fromURL url: URL) throws
  • return json data representation of the configuration

    Declaration

    Swift

    public func jsonData() throws -> Data
  • return json string representation of the configuration

    Declaration

    Swift

    public func jsonString(encoding: String.Encoding = .utf8) throws -> String?