-
Notifications
You must be signed in to change notification settings - Fork 113
Make Lambda.env() -> String? public #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3aa94bb
to
6c793c4
Compare
@@ -44,6 +44,14 @@ public enum Lambda { | |||
self.run(factory: factory) | |||
} | |||
|
|||
/// Utility to access/read environment variables | |||
public static func env(_ name: String) -> String? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we nest this under something like Lambda.Utils
? not sure...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this would make the code just more verbose. I was even unsure if we should put it under Lambda, since it is namespaced by the package in case someone needs it anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not really mind it as such Lambda.env
; not having to import Foundation is a nice goal here.
I'd probably document semantics some more but sounds fine.
I'd -1 ....Utils
since are magnets for tons of random stuff, at least on Lambda
itself one would think twice before adding 10 more random functions 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest having Lambda.Environment
or container of some sort (e.g., env['foo']
). Is Lambda.Context
a suitable "home" for it?
Otherwise I don't really mind Lambda.env
either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Lambda.Context a suitable "home" for it?
Sadly our current Lambda.Context
is not available at Lambda initialization, where it is most likely that we need environment variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, I was thinking to introduce an InitializationContext which will have this + the eventLoop and potential can grow down the line. I think it will make for a more extensible API anyways?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s right. I’m +1 on the ‘InitializationContext’... But we must be aware that if we expose the env only there, in the simple Lambda.run(closure) use case developers have no way to access the env variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since end variables are IMO used for “global effects” might as well make it globally and easily available — so on the Lambda
type statically.
// edit: not really “terrible” global effects, just global effects; config stuff etc; I think it’s useful to have those easy to use when needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay you folks convinced me. @fabianfett would you like to rebase and merge?
Noble goal 👍 |
7279bf3
to
5becf01
Compare
Motivation
Developers need to access environment variables quite often at Lambda startup. We want to save them from importing Foundation. 🙃
Changes
This PR makes our internal access env func public.