I mean, it works, it’s clever, … is it more or less “safe” is my question. 


On May 18, 2023, at 12:02 PM, Felix Dorner <felix.dor...@gmail.com> wrote:


Clojure noob here, I might be totally off the track or committing crimes, so 
please advise.

For ops, I have to often call rest services in different environments, say prod 
and nonprod. My coworkers use postman and clicky clicky stuff, well, not my 
style, I want to use emacs and cider. I've thus written a set of functions that 
call these services, taking the prod/nonprod server as an argument:

(ns services)
(defn rest [server arg1 arg2] ...)

I'm thinking how it would feel to get rid of the server parameter, and resolve 
it inside the function, depending on the current namespace. I can then just 
leave my cider open, use Cider shortcuts to switch to the prod/nonprod 
namespaces quickly and run my stuff. Also, I would be constantly aware of which 
environment I'm in by looking at the repl prompt. Sounds neat somehow. But I 
feel I am venturing off the track somehow, but this seems to work:

(ns prod
  (:require
   [services :refer :all]))

(def server "http://prod-server.com";)

(ns nonprod
  (:require
   [services :refer :all]))

(def server "http://nonprod-server.com";)

(ns services)
;; no more server arg...
(defn call-a [arg1 arg2]
  (let [server @(resolve 'server)]
     ;; ... do stuff with server))

What do I miss? Complete nonsense? Better solutions?
Thanks again for comments,
Felix




-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en 
<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+unsubscr...@googlegroups.com 
<mailto:clojure+unsubscr...@googlegroups.com> .
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/f16c7ac6-107c-48fd-a6af-c9e91687fe18n%40googlegroups.com
 
<https://groups.google.com/d/msgid/clojure/f16c7ac6-107c-48fd-a6af-c9e91687fe18n%40googlegroups.com?utm_medium=email&amp;utm_source=footer>
 .

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/0100018830153cf6-3c4a1729-13a9-472b-aad0-86f85350e7d1-000000%40email.amazonses.com.

Reply via email to