Skip to content

Instantly share code, notes, and snippets.

@alexkehayias
Created August 17, 2012 15:02
Show Gist options
  • Save alexkehayias/3379601 to your computer and use it in GitHub Desktop.
Save alexkehayias/3379601 to your computer and use it in GitHub Desktop.
Setting dotcloud env variables (not working)
(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
Copy link

saolsen commented Aug 17, 2012

(Integer/parseInt (get (System/getenv) "PORT_WWW"))

@saolsen
Copy link

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