Swiftpack.co - Mikroservices/ExtendedConfiguration as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Mikroservices.
Mikroservices/ExtendedConfiguration 1.0.3
:ledger: Library provides mechanism for reading configuration files.
⭐️ 0
🕓 46 weeks ago
macOS
.package(url: "https://github.com/Mikroservices/ExtendedConfiguration.git", from: "1.0.3")

:ledger: ExtendedConfiguration

Build Status Swift 5.3 Vapor 4 Swift Package Manager Platforms OS X | Linux

Library provides mechanism for reading configuration files.

Getting started

You need to add library to Package.swift file:

  • add package to dependencies:
.package(url: "https://github.com/Mikroservices/ExtendedConfiguration.git", from: "1.0.0")
  • and add product to your target:
.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")

Developing

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

Contributing

You can fork and clone repository. Do your changes and pull a request.

GitHub

link
Stars: 0
Last commit: 47 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

Support for UPPERCASED_ environment variables
47 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics