A live poll in Go
Building and compiling
cd poller
go build
go get -u
The default JSON defines 2 polls, the format is:
{
"poll1": {
"pollDescription": "What number do you think is the best?",
"options": {
"1-one": "One is definitely the first",
"2-two": "Two is better than one",
"3-three": "Three is the magic number"
}
},
"poll2": {
"pollDescription": "Another silly poll, choose another number",
"options": {
"1-four": "Four is two plus two",
"2-five": "Five is the number of fingers",
"3-six": "Six is six"
}
}
}
Start several poller servers:
export APP_ID=10000 && ./poller start
export APP_ID=10001 && ./poller start --pollerAddress=localhost:8081
export APP_ID=10002 && ./poller start --pollerAddress=localhost:8082
Start a results server:
./poller results
Vote on different servers, for example:
curl -X POST http://localhost:8080/polls/poll1/1-one
curl -X POST http://localhost:8080/polls/poll1/2-two
curl -X POST http://localhost:8080/polls/poll1/3-three
curl -X POST http://localhost:8081/polls/poll1/2-two
curl -X POST http://localhost:8082/polls/poll1/3-three
curl -X POST http://localhost:8082/polls/poll1/3-three
curl -X POST http://localhost:8080/polls/poll2/1-four
curl -X POST http://localhost:8080/polls/poll2/1-four
curl -X POST http://localhost:8080/polls/poll2/1-four
curl -X POST http://localhost:8081/polls/poll2/2-five
curl -X POST http://localhost:8082/polls/poll2/3-six
The (not so nice, I know) voting GUI can be reached on each poller server:
http://localhost:8080/polls/poll1/leaveyourvote
http://localhost:8081/polls/poll2/leaveyourvote
http://localhost:8082/polls/poll1/leaveyourvote
Observe that results are aggregated on results server:
curl http://localhost:9090/results/polls/poll1
curl http://localhost:9090/results/polls/poll2
Or go to the fantastic results GUI at:
http://localhost:9090/static/results.html?poll=poll1
http://localhost:9090/static/results.html?poll=poll2
This image is built using the official golang image
sudo docker build .
This image is built just with the binary and is just a few Mb.
CGO_ENABLED=0 go build -a -installsuffix cgo -o poller .
sudo docker build -f Dockerfile.minimal .
./poller start -h
./poller results -h
First, import the template into OpenShift:
oc create -f poller-openshift-template.yml -n openshift
Deploy the service Poller from the service catalog.
Enable the multicast into the project where you deployed the Poller.
oc annotate netnamespace <project> netnamespace.network.openshift.io/multicast-enabled=true
Create the project.
oc new-project <project>
Enable the multicast into the project.
oc annotate netnamespace <project> netnamespace.network.openshift.io/multicast-enabled=true
Deploy the app.
oc new-app --template=poller-template -p APP_REPO=<gitRepo> -p APP_NAME=<name> -p APP_DOMAIN=<domain>