bitbucket.org/oscaroscar/vostok
Vostok
- What Vostok can do
- If you do not have Go yet
- How to install Vostok’s dev environment
- Using the examples
- 1. The ‘simple’ example
- Simple webapp: building
- Simple webapp: running
- Simple webapp: ‘forever running’
- 2. The ‘simple JSON’ example
- 3. The ‘simple DB’ example
- 4. The ‘REST’ example
- 1. The ‘simple’ example
- Some coding principles
- Need some tools ?
What Vostok can do
- Vostok’s core services
- The REST layer
- The Admin functionalities
Top
If you do not have Go yet
There are several ways to setup Go.
With macOS, a straightforward way is the following:
- Install brew, if you do not already have it. Learn a bit how to use it.
- Then:
brew install go
- Create a common folder for all your Go projects (mandatory), for example:
mkdir -p ~/Git/Go
- Then, add to your bash env file (providing you followed the same paths - else just adapt this):
export GOROOT=/usr/local/opt/go/libexec
export GOPATH=$HOME/Git/Go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Top
How to install Vostok’s dev environment
cd $GOPATH/src
mkdir -p bitbucket.org/oscaroscar && cd bitbucket.org/oscaroscar
And then git clone
vostok here.
Finally, to be able to use Vostok
in another Go program:
go install -v bitbucket.org/oscaroscar/vostok
To build Vostok
while developing it:
go build -i -v bitbucket.org/oscaroscar/vostok
Unless you already have you preferences, you really should consider the Atom editor, with the go-plus package, to have quite an IDE for Go.
Top
Using the examples
1. The ‘simple’ example
What we want to do here is to install a very very simple application server and to make it run so we can send HTTP resquests to it and see something in return.
Simple webapp: building
Let’s build it:
go build -i -o $GOPATH/src/bitbucket.org/oscaroscar/vostok/examples/simple/examples_vostok_simple -v bitbucket.org/oscaroscar/vostok/examples/simple/go
Explanations:
-i
: to automatically install the dependencies if needed-o $GOPATH/src/bitbucket.org/oscaroscar/vostok/bin/examples/simple/examples_vostok_simple
: the output is a binary file namedexamples_vostok_simple
-v
: a kind of verbose mode, to see what needs to be rebuilt along the waybitbucket.org/oscaroscar/vostok/examples/simple/go
: the path to the Go files to build
Top
Simple webapp: running
To run the webapp, we need a config
file - such as the one you can find in the /conf
folder, that you can duplicate and adapt:
cd $GOPATH/src/bitbucket.org/oscaroscar/vostok/examples/simple && sudo ./examples_vostok_simple -config=conf/examples.vostok.simple.test.mymachine.json
Depending on where the log is done - which is configured within the given config file - you might need to sudo
the running of the server (which we do in the example above).
To look at the logs - which is highly recommended - you can tail -f
the logging file.
To check that it works, open this URL in your web browser: http://localhost:64900/examples/vostok/simple
, setting the host and port corresponding to the config file you’re using.
Top
Simple webapp: ‘forever running’
You can write scripts that will basically run the server as seen below in a never ending loop. An example is given here:
cd $GOPATH/src/bitbucket.org/oscaroscar/vostok/examples/simple && sudo scripts/forever.test.mymachine.sh
Top
2. The ‘simple JSON’ example
This example shows Vostok’s ability to return JSON responses.
If you’ve gone through the ‘simple’ example, we can go quicker here. To build:
go build -i -o $GOPATH/src/bitbucket.org/oscaroscar/vostok/examples/simpleJSON/examples_vostok_simpleJSON -v bitbucket.org/oscaroscar/vostok/examples/simpleJSON/go
To run:
cd $GOPATH/src/bitbucket.org/oscaroscar/vostok/examples/simpleJSON && sudo ./examples_vostok_simpleJSON -config=conf/examples.vostok.simpleJSON.test.mymachine.json
To test, open http://localhost:64901/examples/vostok/simple
in your navigator.
Top
3. The ‘simple DB’ example
The simpleDB application makes use of vostok and shows how to build an application connected to a database.
In order to demonstrate its capacity to use various DB manager, we have written two sets of config files and two sets of database creation scripts so the app can connect PostgreSQL or MySQL.
The instructions can be found here.
To build:
go build -i -o $GOPATH/src/bitbucket.org/oscaroscar/vostok/examples/simpleDB/examples_vostok_simpleDB -v bitbucket.org/oscaroscar/vostok/examples/simpleDB/go
To run (MySQL):
cd $GOPATH/src/bitbucket.org/oscaroscar/vostok/examples/simpleDB && sudo ./examples_vostok_simpleDB -config=conf/examples.vostok.simpleDB.mysql.test.mymachine.json
Or (PostgreSQL):
cd $GOPATH/src/bitbucket.org/oscaroscar/vostok/examples/simpleDB && sudo ./examples_vostok_simpleDB -config=conf/examples.vostok.simpleDB.postgres.test.mymachine.json
To “forever run”:
cd $GOPATH/src/bitbucket.org/oscaroscar/vostok/examples/simpleDB && sudo scripts/forever.test.mymachine.sh
To test, open http://localhost:64901/examples/vostok/simple
in your navigator.
Top
4. The ‘REST’ example
If can be found here.
Top
Some coding principles
Some rules are applied to ensure code homogeneity inside this lib, and preferably in all projects using it:
- Using of goreturns, which applies goimports, itself calling gofmt.
- Using of gometalinter like this:
gometalinter --config ./gometalinter.json packages/./...
Top
Need some tools ?
- You can try Atom, with the go-plus plugin. To use the bundled plugin go-debug, you’ll need to install delve.
- [Give other possible methods here (Vim, Vscode, etc.)]
Top