Envy is an enviroment variable manager, based off of SwiftDotEnv. It uses
@dynamicMemberLookup, subscripts, and generic functions to retrieve information, type-checked, from your
.env file on the server.
All the tests are passing and this is currently a production-ready library. Feel free to submit issues or pull-requests for cases in which you find it not to work.
I recommend you use Swift Package Manager to use Envy in your server-side project. Add this line to your
Package.swift, as an element in your package's dependencies, run
swift package fetch (or any superset of that command), and you should be all set:
.package(url: "https://github.com/markmals/Envy", from: "1.0.0"),
If this is your
DB_HOST=test.com DB_PORT=1234 IS_ENABLED=0
Then this code will extract its variables for use in Swift:
import Envy let env = Envy(with: ".env") let host: String = env.DB_HOST ?? "localhost" let port: Int = env.DB_PORT ?? 3306 let isEnabled: Bool = env.IS_ENABLED ?? true
See the tests for more usage examples.