Skip to content

Commit

Permalink
Move from json to hjson for the configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
elwinar committed Oct 27, 2016
1 parent 9204467 commit e30eac4
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

## [3.4.0](https://github.com/elwinar/rambler/releases/tag/v3.4.0) - 2016-10-27

### Added

- HJSON support for the configuration file

## [3.3.0](https://github.com/elwinar/rambler/releases/tag/v3.3.0) - 2016-07-13

### Added
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Rambler configuration is lightweight: just dump the credentials of your database

When running, rambler will try to find a configuration file in the working directory and use its values to connect to the managed database.

#### HJSON

Rambler now supports [HJSON](http://hjson.org/) configuration files, which is by the way retrocompatible with JSON.

#### Drivers

Rambler supports actually 3 drivers:
Expand Down
7 changes: 4 additions & 3 deletions configuration.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"encoding/json"
"fmt"
"github.com/imdario/mergo"
"io/ioutil"

"github.com/client9/xson/hjson"
"github.com/imdario/mergo"
)

// Configuration is the configuration type
Expand All @@ -22,7 +23,7 @@ func Load(filename string) (Configuration, error) {
return c, err
}

err = json.Unmarshal(raw, &c)
err = hjson.Unmarshal(raw, &c)
if err != nil {
return c, err
}
Expand Down
27 changes: 27 additions & 0 deletions configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ func TestLoad(t *testing.T) {
},
},
},
{
input: "test/valid.hjson",
err: false,
output: Configuration{
Environment: Environment{
Driver: "mysql",
Protocol: "tcp",
Host: "localhost",
Port: 3306,
User: "root",
Password: "",
Database: "rambler_default",
Directory: ".",
},
Environments: map[string]Environment{
"testing": {
Database: "rambler_testing",
},
"development": {
Database: "rambler_development",
},
"production": {
Database: "rambler_production",
},
},
},
},
}

for n, c := range cases {
Expand Down
21 changes: 21 additions & 0 deletions test/valid.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
driver: mysql
protocol: tcp
host: localhost
port: 3306
user: root
password: ""
database: rambler_default
directory: .
environments: {
testing: {
database: rambler_testing
}
development: {
database: rambler_development
}
production: {
database: rambler_production
}
}
}

0 comments on commit e30eac4

Please sign in to comment.