Dealing with edn for the first time

286 views
Skip to first unread message

Hussein B.

unread,
Apr 20, 2014, 11:15:09 AM4/20/14
to clo...@googlegroups.com
Hi,

I want to save the configuration of my application in edn file.

Lein is used (of course). I want to pub my config.edn under /resources directory.

But honestly, I don't know the format of edn. I tried to google it, but I didn't get anything helpful. The format is in its early stages.

So, my questions:

1) What is the equivalent of the following in edn:

database.url=localhost
username=foo
password=bar

2) Since my edn file is under /resources . I need a way to read from the classpath.
How to do this?

Thanks for help and time.

Mike Haney

unread,
Apr 20, 2014, 11:55:53 AM4/20/14
to clo...@googlegroups.com
1. In its simplest form, EDN is just clojure data literals. So for simple cases like configuration, just use a map:

{ :database-uri "some-uri"
:another-param "some value"
:debug-mode true }

2. You can use clojure.java.io/resource to access resources, but for config files you usually don't want them as resources, since those will be embedded in the jar/war file when you deploy, making it difficult to configure for different deployment environments.

I have some generic code for loading config files that I use in most projects now. I originally lifted it from some open-source project at one point (can't remember which, or I would give credit). I'll create a gist and post the link in a bit.

Mike Haney

unread,
Apr 20, 2014, 12:21:07 PM4/20/14
to clo...@googlegroups.com
Found the project I lifted my config code from, it's this one:  https://github.com/bellkev/dacom

Look through that, it should give you a good starting point.  If you still have questions, feel free to ask and we'll try to help.

Mark Mandel

unread,
Apr 20, 2014, 9:04:19 PM4/20/14
to clojure
I wrote a blog post a while back on working with EDN, which could be helpful:

From there, fire up a REPL, load in clojure.edn, and start converting vectors and maps to EDN and see what the format looks like :)

Mark


On Mon, Apr 21, 2014 at 2:21 AM, Mike Haney <txmik...@gmail.com> wrote:
Found the project I lifted my config code from, it's this one:  https://github.com/bellkev/dacom

Look through that, it should give you a good starting point.  If you still have questions, feel free to ask and we'll try to help.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
Reply all
Reply to author
Forward
0 new messages