github.com/gocaveman/caveman@v0.0.0-20191211162744-0ddf99dbdf6e/dbutil/validation.go (about)

     1  package dbutil
     2  
     3  // something to scan struct fields for common validation - so you can tag your structs with things like
     4  // min and max length, email formatted, whatever.
     5  // helper func makes this a one-liner to implement a Validate() error function on a model object, with
     6  // a return value that can be WriteJSON or whatever and is useful in the browser
     7  // the whole idea is that validation is really just a convention along with a helper func or two
     8  // no depdendency on a particular ORM or that an ORM is used at all
     9  
    10  // think about if it makes sense to generate default HTML form elements from this validation data
    11  // - it could be a simple crutch to build a form very rapidly; it's an odd collapse of tiers
    12  //   but it also shouldn't introduce dependnecies or other weird stuff - it's really just a
    13  //   helper
    14  
    15  // we're going to need gorm (or sqlx/modl!) tooling for looking up relations and other basic
    16  // record operations in HTML (in a form), otherwise you end up writing a controller that
    17  // has to load all kinds of crap that really isn't controller-specific - it's just simple
    18  // data calls needed by the page.  maybe we should preclude any operations which write! (probably should)
    19  
    20  // default "controllers" - FormController, ListController from OctoberCMS - although maybe not, might
    21  // be better to code generate (cmd line tool) simple controllers that have the REST endpoint stuff on
    22  // them and use helper funcs to make them efficient and concise - this is probably better than some
    23  // bit giant class that you extend and configure
    24  // cmd line to generate a bunch of crap for a particular model