vapor / service

📦 Dependency injection / inversion of control framework.
MIT License
85 stars 9 forks source link

Environment Decoder #31

Open tanner0101 opened 5 years ago

tanner0101 commented 5 years ago

A decoder for initializing structs from environment variables would be a nice addition to this package.

struct MyConfigVars: Decodable {
    var mysqlURL: String
    var googleToken: String
    var fooID: Int
}

var env = try Environment.detect()
let myConfig = try EnvironmentDecoder().decode(MyConfigVars.self, from: env)

print(myConfig.mysqlURL) // String

This decoder would automatically translate camelCase var names to UPPER_SNAKE_CASE.