Skip to content

Commit

Permalink
Merge branch 'hjson'
Browse files Browse the repository at this point in the history
  • Loading branch information
elwinar committed Oct 27, 2016
2 parents 7e232b8 + e30eac4 commit 4b04113
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 13 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
25 changes: 16 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ TARGETS="windows/amd64,windows/386,darwin/amd64,darwin/386,linux/amd64,linux/386
LDFLAGS="-X main.VERSION=`git describe --tags`"
PKG="github.com/elwinar/rambler"

help: ## Get help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}'
default: build
all: fetch build test

.PHONY: build
build: ## Build the binary for the local architecture
@go build --ldflags=$(LDFLAGS)
go build --ldflags=$(LDFLAGS)

test: ## Test the project
@go test ./...
.PHONY: fetch
fetch: ## Fetch the dependencies
go get ./...

release: ## Build the release files
@xgo --targets=$(TARGETS) --ldflags=$(LDFLAGS) $(PKG)
.PHONY: help
help: ## Get help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}'

.PHONY: build test
.PHONY: release
release: ## Build the release files
xgo --targets=$(TARGETS) --ldflags=$(LDFLAGS) $(PKG)

.DEFAULT_GOAL := build
.PHONY: test
test: ## Test the project
go test ./...
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
15 changes: 14 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
Vagrant.configure(2) do |config|
config.vm.box = "elwinar/golang"
config.vm.box = "kaorimatz/archlinux-x86_64"
config.vm.synced_folder ".", "/home/vagrant/src/github.com/elwinar/rambler"
config.vm.provision "shell", inline: <<EOS
chown vagrant:users -R /home/vagrant
echo "Server = https://mirror.compojoom.com/archlinux/$repo/os/$arch
Server = http://mirror.archlinux.ikoula.com/archlinux/$repo/os/$arch
Server = http://archlinux.de-labrusse.fr/$repo/os/$arch
Server = http://mir.archlinux.fr/$repo/os/$arch
Server = http://archlinux.mirror.root.lu/$repo/os/$arch
" >> /etc/pacman.d/mirrorlist
pacman -Syy --noconfirm
pacman -S --noconfirm go git subversion mercurial bzr
echo "export GOPATH=~
export PATH=\$GOPATH/bin:\$PATH
" >> /home/vagrant/.bashrc
EOS
end
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 4b04113

Please sign in to comment.