Now that Jiffy is installed, we will build a simple service to test it out.
Jiffys source tree comes with a number of sample model files that you can be used to get the hang of things. We are going to use a simple model file that contains an entity named ‘Person’. The model file can be found in the Jiffy source tree, or pulled directly from the Jiffy github repository.
For now we are not going to worry about the content of the model file, but we will look at the structure of our new ‘Person’ entity briefly.
// Person structure
type Person struct {
ID uint64 `json:"id" sqac:"primary_key:inc;start:10000000"`
Href string `json:"href" sqac:"-"`
Name *string `json:"name,omitempty" sqac:"nullable:true;index:non-unique"`
Age *uint `json:"age,omitempty" sqac:"nullable:true"`
Weight *float64 `json:"weight,omitempty" sqac:"nullable:true"`
ValidLicense *bool `json:"valid_license,omitempty" sqac:"nullable:true;index:non-unique"`
}
We can see that Jiffy will create a ‘Person’ model with a small set of fields, each with a number of attributes. For the moment, we will concern ourselves only with the field names and types, as we will need to use this information to construct some test data for the new service.
‘sqac’ tags are used to pass information to Jiffys ORM layer.
Create a new target directory for the project under $GOPATH/src.
cd $GOPATH/src
mkdir jiffy_tests
Execute the jiffy binary, specifying the model file to use, as well as the target directory/project name.
jiffy -m $GOPATH/src/github.com/1414C/jiffy/support/testing_models/simpleSingleEntityModel.json -p /jiffy_tests/first_app
-m tells jiffy which model file should be used to construct the new service.
-p tells jiffy where to write the generated application code.
Note that the location of the folder specified by the -p flag is deemed to be relative to $GOPATH/src.
If everything has gone according to plan, a new application has been generated and should be ready to run. Let’s take a look at what jiffy generated for us!
cd $GOPATH/src/jiffy_tests/first_app
ls -l
This should result in a list of the files and folders comprising our new application.
drwxr-xr-x 12 stevem staff 384 5 Feb 21:44 .
drwxr-xr-x 10 stevem staff 320 5 Feb 21:44 ..
-rwxr-xr-x 1 stevem staff 588 5 Feb 21:44 .dev.config.json
-rwxr-xr-x 1 stevem staff 611 5 Feb 21:44 .prd.config.json
drwxr-xr-x 4 stevem staff 128 5 Feb 21:44 appobj
drwxr-xr-x 10 stevem staff 320 5 Feb 21:44 controllers
drwxr-xr-x 4 stevem staff 128 5 Feb 21:44 jwtkeys
-rwxr-xr-x 1 stevem staff 839 5 Feb 21:44 main.go
-rwxr-xr-x 1 stevem staff 18421 5 Feb 21:44 main_test.go
drwxr-xr-x 3 stevem staff 96 5 Feb 21:44 middleware
drwxr-xr-x 12 stevem staff 384 5 Feb 21:44 models
drwxr-xr-x 3 stevem staff 96 5 Feb 21:44 util
$
Jiffy generates two sample configuration files each time it is executed. We are going to run our application with development environment settings, so lets take a quick look at the .dev.config.json file to make sure there are no horrible surprises.
{
"external_address": "127.0.0.1:3000",
"internal_address": "127.0.0.1:4444",
"env": "dev",
"ping_cycle": 1,
"failure_threshold": 5,
"pepper": "secret-pepper-key",
"hmac_Key": "secret-hmac-key",
"database": {
"db_dialect": "sqlite",
"host": "",
"port": 0,
"usr": "",
"password": "",
"name": "testdb.db",
"ormLogActive": true,
"ormDebugTraceActive": false
},
"group_leader_kvs": {
"local_standalone": {
"active": true,
"internal_address": "127.0.0.1:4444"
},
"redis": {
"active": false,
"max_idle": 80,
"max_active": 12000,
"redis_protocol": "tcp",
"redis_address": "127.0.0.1:6379"
},
"memcached": {
"active": false,
"memcached_addresses": [
"192.168.112.50:11211"
]
},
"sluggo": {
"active": false,
"sluggo_address": "127.0.0.1:7070"
}
},
"logging": {
"active": true,
"callLocation": true,
"colorMsgTypes": true,
"infoMsgs": false,
"warningMsgs": false,
"errorMsgs": true,
"debugMsgs": false,
"traceMsgs": false
},
"cert_file": "",
"key_file": "",
"rsa256_priv_key_file": "",
"rsa256_pub_key_file": "",
"rsa384_priv_key_file": "",
"rsa384_pub_key_file": "",
"rsa512_priv_key_file": "",
"rsa512_pub_key_file": "",
"ecdsa256_priv_key_file": "",
"ecdsa256_pub_key_file": "",
"ecdsa384_priv_key_file": "jwtkeys/ecdsa384/ec384.priv.pem",
"ecdsa384_pub_key_file": "jwtkeys/ecdsa384/ec384.pub.pem",
"ecdsa521_priv_key_file": "",
"ecdsa521_pub_key_file": "",
"jwt_sign_method": "ES384",
"jwt_lifetime": 120,
"service_activations": [
{
"service_name": "Person",
"service_active": true
}
]
}
Jiffy decides by default to run against a sqlite database and generates what should be a suitable configuration file for most systems. Again, we are not going to worry too much about what is in the configuration file at this point, but know that database file ‘testdb.db’ will be created in the generated application’s root folder. For more information regarding the content of the configuration files see the Application Configuration Overview section of this document.