-
Notifications
You must be signed in to change notification settings - Fork 7
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
Using environment variables for integer values #4
Comments
@lpsmith any thoughts? |
Oh, sorry for taking so long to get back to you. So just a quick response for now: Overall, I like the idea of allowing interpolation of value types other than strings, though there are a few small issues to consider. Nothing I foresee as any big deal though. One possible workaround, is that you can use the Functor instance to allow strings or numbers in your parser, basically by allowing a string value that also happens to be a number. Or you can write your own ValueParser that does this. Though, I'm probably missing some things in the public API to write this sort of ValueParser nicely... |
I found a workaround: coerceInt :: (Read i, Integral i) => Value -> Maybe i
coerceInt (Number x) = rightToMaybe $ floatingOrInteger x
coerceInt (String x) = readMaybe $ toS x
coerceInt _ = Nothing Then I can do |
Yeah, that's pretty close to one of the workarounds I had in mind, though perhaps done a little bit nicer. One downside is that this particular workaround will just default to port You could write your own Either way, this requires a workaround in the source code, whereas from an operational perspective it might be nice for a system admin to be able to do this without having the programmers anticipate this particular use case. So I think what would be acceptable is to be able to write Also, I'm a bit annoyed that configurator chose So I think the proper resolution to this issue is twofold:
|
Thanks for your consideration. If you do extend settings like |
Yeah, after reviewing the current string syntax, unfortunately there doesn't seem to be a very nice migration path for strings; the conservative approach would be to introduce a new string syntax denoted by prefixing a character or something, e.g. In any case, I definitely will add environment interpolation for bools and integers eventually. |
My configuration file contains a field for a web server port. I'd like to read the value from an environment variable, but doing so always treats it as a string.
Running with FOO exported to 3000 causes this error:
I tried this too
server-port = $(FOO)
but it reports
ParseError "test.conf" "endOfInput"
.Is there something I can do in my code to allow both literal integers and those from environment variables?
(Context: PostgREST/postgrest#826)
The text was updated successfully, but these errors were encountered: