-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ini loading to return change events
- Loading branch information
Showing
16 changed files
with
872 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
.PHONY: start-containers stop-containers test examples all glide-deps | ||
.DEFAULT_GOAL := all | ||
|
||
# GO | ||
GOPATH := $(shell go env | grep GOPATH | sed 's/GOPATH="\(.*\)"/\1/') | ||
GLIDE := $(GOPATH)/bin/glide | ||
PATH := $(GOPATH)/bin:$(PATH) | ||
export $(PATH) | ||
|
||
export ARGS_DOCKER_HOST=localhost | ||
DOCKER_MACHINE_IP=$(shell docker-machine ip default 2> /dev/null) | ||
ifneq ($(DOCKER_MACHINE_IP),) | ||
ARGS_DOCKER_HOST=$(DOCKER_MACHINE_IP) | ||
endif | ||
|
||
ETCD_DOCKER_IMAGE=quay.io/coreos/etcd:latest | ||
|
||
start-containers: | ||
@echo Checking Docker Containers | ||
@if [ $(shell docker ps -a | grep -ci args-etcd) -eq 0 ]; then \ | ||
echo Starting Docker Container args-etcd; \ | ||
docker run -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \ | ||
--name args-etcd $(ETCD_DOCKER_IMAGE) /usr/local/bin/etcd \ | ||
--name etcd0 \ | ||
--advertise-client-urls http://${ARGS_DOCKER_HOST}:2379,http://${ARGS_DOCKER_HOST}:4001 \ | ||
--listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \ | ||
--initial-advertise-peer-urls http://${ARGS_DOCKER_HOST}:2380 \ | ||
--listen-peer-urls http://0.0.0.0:2380 \ | ||
--initial-cluster-token etcd-cluster-1 \ | ||
--initial-cluster etcd0=http://${ARGS_DOCKER_HOST}:2380 \ | ||
--initial-cluster-state new; \ | ||
elif [ $(shell docker ps | grep -ci args-etcd) -eq 0 ]; then \ | ||
echo restarting args-etcd; \ | ||
docker start args-etcd > /dev/null; \ | ||
fi | ||
|
||
stop-containers: | ||
@if [ $(shell docker ps -a | grep -ci args-etcd) -eq 1 ]; then \ | ||
echo Stopping Container args-etcd; \ | ||
docker stop args-etcd > /dev/null; \ | ||
fi | ||
|
||
test: start-containers | ||
@echo Running Tests | ||
export ETCDCTL_ENDPOINTS=${ARGS_DOCKER_HOST}:2379 | ||
export ETCDCTL_API=3 | ||
go test . -v | ||
|
||
|
||
all: examples | ||
|
||
examples: | ||
go install $(shell go list ./... | grep -v vendor) | ||
|
||
travis-ci: glide-deps start-containers | ||
go get -u github.com/mattn/goveralls | ||
go get -u golang.org/x/tools/cmd/cover | ||
go get -u golang.org/x/text/secure/bidirule | ||
goveralls -service=travis-ci | ||
|
||
$(GLIDE): | ||
go get -u github.com/Masterminds/glide | ||
|
||
go-deps: | ||
go get golang.org/x/net/context | ||
go get github.com/onsi/ginkgo | ||
go get github.com/onsi/gomega | ||
go get github.com/pborman/uuid | ||
|
||
glide-deps: $(GLIDE) go-deps | ||
$(GLIDE) install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[![Coverage Status](https://img.shields.io/coveralls/thrawn01/args-etcd.svg)](https://coveralls.io/github/thrawn01/args-etcd) | ||
[![Build Status](https://img.shields.io/travis/thrawn01/args-etcd/master.svg)](https://travis-ci.org/thrawn01/args-etcd) | ||
|
||
## Introduction | ||
This repo provides an ini key=value storage backend for use with | ||
[args](http://github.com/thrawn01/args) | ||
|
||
## Installation | ||
``` | ||
$ go get github.com/thrawn01/argsini | ||
``` | ||
|
||
## Usage | ||
```go | ||
import ( | ||
"github.com/thrawn01/args" | ||
"github.com/thrawn01/argsini" | ||
) | ||
|
||
parser := args.NewParser() | ||
parser.AddOption("listen-address").Help("Specify local address to listen on") | ||
parser.AddOption("config").Short("c").Required().Default("/etc/app/config.ini"). | ||
Help("Specify configuration file") | ||
parser.AddOption("cache-size").IsInt().Default(150). | ||
Help("Specify the size of the cache in entries") | ||
|
||
// Parse the command line args | ||
opt := parser.ParseOrExit(nil) | ||
|
||
// Create a new backend object | ||
backend := argsini.NewFromFile(opt.String("config"), "") | ||
|
||
// Load the config file specified on the command line | ||
opts, err := parser.FromBackend() | ||
if err != nil { | ||
fmt.Printf("config error - %s\n", err.Error()) | ||
} | ||
|
||
// Print out the loaded config items | ||
fmt.Printf("listen-address: %s\n", opts.String("listen")) | ||
fmt.Printf("cache-size: %d\n", opts.Int("listen")) | ||
|
||
// Watch ini file for any configuration changes | ||
cancelWatch := parser.Watch(backend, func(event *args.ChangeEvent, err error) { | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
fmt.Printf("Changed Event - %+v\n", event) | ||
// This takes a ChangeEvent and update the opts with the latest changes | ||
parser.Apply(opts.FromChangeEvent(event)) | ||
}) | ||
``` |
Oops, something went wrong.