Contents Page Previous Next

The Goblimey Scaffolder

2.3 Running the Scaffolder

The scaffolder takes the JSON specification and produces a web server that manages the database tables described by the JSON. The first time you run the server, it creates the tables.

By default the scaffolder generates a Go project in the current directory, which should be your github project directory (in the example, goprojects/src/github.com/alunsmithie/animals). Alternatively you can run it from another directory and tell it where to find the project directory.

When you run the scaffolder, by default it looks for a file "scaffold.json" in the current directory defining the database - something like the example above. You can specify a different file.

To get started, there is a version of the example JSON in the scaffolder source code. In your Go workspace, look in src/github.com/goblimey/scaffolder/examples. Copy the file animals.scaffold.json to your project directory, rename it scaffold.json and edit it to set the source base of your project. If you created a github account and a project, the source base value will be something like "github.com/alunsmithie/animals". If you just created a directory in goprojects/src, it will be the name of that directory.

In your command window, cd to your project directory and then run the scaffolder like so:


    $ scaffolder
	

That creates the source code of your web server and some scripts. On Linux, install.sh builds and installs the server:


   $ ./install.sh
	

On Windows, install.bat does the same:


    install
	

There is also test.sh and test.bat. These run tests to ensure that the generated code works . For example, on Linux:


    $ ./test.sh
	

If you edit the JSON and run the scaffolder again it will produce a new version of the server. HOWEVER it only creates database tables if they don't already exist. If you add extra fields, use the mysql client to drop the tables before you start the server. It will then create new ones. Dropping the tables will destroy any data that you have created. Alternatively, leave your project as it is and create a new one that uses a different database. (This is why you might not want to create a public project on the github just to do a bit of prototyping.)

To specify the JSON file:


    $ scaffolder ../specs/animals.json
	

To specify the workspace directory as well:


    $ scaffolder workspace=/home/simon/goprojects ../specs/animals.json
	

Run the scaffolder program like so to see all of the options:


    $ scaffolder -h
    Usage of scaffolder:
      -overwrite
          overwrite all files, not just the generated directory
     -projectdir string
          the project directory (default ".")
     -templatedir string
          the directory containing the scaffold templates (normally this is not specified and built in templates are used)
      -v enable verbose logging (shorthand)
      -verbose
          enable verbose logging
	

The scaffolder creates

It's assumed that you may want to tweak things like the scripts, the main program, the home page and so on. If you run the scaffolder over this project again, by default only the stuff in the "generated" directories is overwritten.

If you run the scaffolder with the overwrite option, it replaces everything.

The project includes tests which are run by the test script test.sh (or test.bat on Windows). This can run the unit tests, the integration tests or (by default) both. NOTE that some integration tests use the real database. It's safe to run them now, but if you run them after you've been playing with the web server, any data that you have set up will be trashed.

    $ ./test.sh unit
	
runs just the unit tests, and that's always safe.

Contents Page Previous Next