Created
August 17, 2012 15:02
-
-
Save alexkehayias/3379601 to your computer and use it in GitHub Desktop.
Setting dotcloud env variables (not working)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro maybe | |
"Assuming that the body of code returns X, this macro returns [X nil] in the case of no error | |
and [nil E] in event of an exception object E." | |
[& body] | |
`(try [(do ~@body) nil] | |
(catch Exception e# | |
[nil e#]))) | |
(defn safe-slurp | |
"Slurp content of given filename. Return nil on error reading the file." | |
[filename] | |
(let [[text ex] (maybe (slurp filename))] | |
(if ex nil text))) | |
;; Define dotcloud environmental values | |
(defn port [& args] | |
"Set the port based on the environment" | |
(or | |
(:PORT_WWW (generate-string (safe-slurp "/home/dotcloud/environment.json"))) | |
(int 8000))) |
saolsen
commented
Aug 17, 2012
or more completely
(defn port [& args]
(if-let [port (get (System/getenv) "PORT_WWW")]
(Integer/parseInt port)
8080))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment