Library provides mechanism for reading configuration files.
You need to add library to Package.swift
file:
.package(url: "https://github.com/Mikroservices/ExtendedConfiguration.git", from: "1.0.0")
.target(name: "App", dependencies: [
.product(name: "Vapor", package: "vapor"),
.product(name: "ExtendedConfiguration", package: "ExtendedConfiguration")
])
Then you can add configuration loading during startup Vapor project:
try app.settings.load([
.jsonFile("appsettings.json", optional: false),
.jsonFile("appsettings.\(self.environment.name).json", optional: true),
.environmentVariables(.withPrefix("smtp"))
])
Each configuration item will override items from previous files. Your appsettings.json
file can look like on below snippet:
{
"smtp": {
"fromName": "Mikroservice",
"fromEmail": "[email protected]",
"hostname": "[email protected]",
"port": 465,
"username": "username",
"password": "P@ssword",
"secure": "none"
}
}
Now you can read configuration:
let variable = request.application.settings.getString(for: "smtp.fromEmail")
Download the source code and run in command line:
$ git clone https://github.com/Mikroservices/ExtendedConfiguration.git
$ swift package update
$ swift build
Run the following command if you want to open project in Xcode:
$ open Package.swift
You can fork and clone repository. Do your changes and pull a request.
link |
Stars: 0 |
Last commit: 47 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics