Swiftpack.co - Package - Mikroservices/ExtendedConfiguration

: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": "info@server.com",
        "hostname": "smtp@server.com",
        "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

Dependencies

Used By

Total: 0

Releases

Add all() function - 2020-09-27 18:58:17

Add interface for custom settings objects - 2020-09-27 18:44:50

Now there is possibility to store own settings object:

app.settings.set(YourClass(.....), for: YourClass.self)

You can get object in application:

let settings = app.settings.get(YourClass.self)

First release of extended configuration lib for Vapor - 2020-09-27 11:51:40