Skip to content
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

funcool.struct as validation library? #23

Open
px0 opened this issue Aug 21, 2018 · 4 comments
Open

funcool.struct as validation library? #23

px0 opened this issue Aug 21, 2018 · 4 comments

Comments

@px0
Copy link

px0 commented Aug 21, 2018

Have you checked out https://funcool.github.io/struct/latest/ as validation library? The featureset seems to be comparable to verily, except that struct is offering optional coercion and I like the way that custom validators are created better. Here is an example of a validator for a moustache-templated text I wrote:

(def valid-template
  {:message "Die Variablen müssen in {{}} eingeschlossen werden"
   :optional true
   :state false
   :validate (fn [v]
               (let [freq (frequencies v)]
                 (and (even? (get freq \{ 0))
                      (= (get freq \{)
                         (get freq \})))))
   :coerce (fn [s] ;  lower-case and trim anything in {{}}
             (str/replace s
                          #"\{\{(.+?)\}\}"
                          #(str "{{"
                                (str/lower-case (str/trim (second %1)))
                                "}}")))})
@swlkr
Copy link
Member

swlkr commented Aug 21, 2018

I like this, I actually wrote some custom code on the current validator to get it back into a map, this lib already returns a vector of [error map]

@swlkr
Copy link
Member

swlkr commented Sep 23, 2018

This is still coming along, but I also wanted to start to try to let people customize which functions do what, so like… when you start the app in server.clj you could pick what happens, like this:

(ns server
  (:require [coast]))

(def routes [[:get "/" :home]])

(def app (coast/app {:routes routes
                     :router custom-router
                     :validate custom-validation-fn-or-library
                     :email custom-emailer
                     :queue-job custom-job-queuer})) ; and so on

This also means that the coast lib itself in clojars, won't have like 20 deps anymore, the template might have a bunch of deps in it, so if you want to customize the renderer or what have you, you'd choose what you want. Just trying to keep you in the loop, if you're still into it 👍

@px0
Copy link
Author

px0 commented Sep 24, 2018

I am, and I appreciate it :) I haven't had much time lately to play with Coast, but I've been following the issues and your commits! Thanks for your work!

@px0
Copy link
Author

px0 commented Sep 24, 2018

BTW, I wouldn't worry too much about making everything ultra configurable. If I really, really want a different router I can rip it out myself, it's probably not worth making the code base super complicated for the common case. YAGNI and all that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants