influxdb/CONTRIBUTING.md

127 lines
4.1 KiB
Markdown
Raw Normal View History

2014-07-15 16:52:17 +00:00
Contributing to InfluxDB
========================
2014-07-15 20:01:33 +00:00
InfluxDB follows standard Go project structure. This means that all
2014-07-15 16:52:17 +00:00
your go development are done in $GOPATH/src. GOPATH can be any
directory under which InfluxDB and all it's dependencies will be
cloned. For more details on recommended go project's structure, see
[How to Write Go Code](http://golang.org/doc/code.html) and
2014-09-28 18:06:45 +00:00
[Go: Best Practices for Production Environments](http://peter.bourgon.org/go-in-production/), or you can just follow
2014-07-15 16:52:17 +00:00
the steps below.
Signing the CLA
---------------
If you are going to be contributing back to InfluxDB please take a
second to sign our CLA, which can be found
[on our website](http://influxdb.com/community/cla.html)
2014-11-03 02:14:31 +00:00
Installing go
-------------
2014-07-15 16:52:17 +00:00
We recommend using gvm, a Go version manager. For instructions
2014-07-15 16:52:17 +00:00
on how to install see
[the gvm page on github](https://github.com/moovweb/gvm). InfluxDB
currently works with Go 1.4 and up.
2014-07-15 16:52:17 +00:00
After installing gvm you can install and set the default go version by
running the following:
gvm install go1.4
gvm use go1.4 --default
2014-07-15 16:52:17 +00:00
Revision Control Systems
------
Go has the ability to import remote packages via revision control systems with the `go get` command. To ensure that you can retrieve any remote package, be sure to install the following rcs software to your system.
Currently the project only depends on `git` and `mercurial`.
[Install Git](http://git-scm.com/book/en/Getting-Started-Installing-Git)
[Install Mercurial](http://mercurial.selenic.com/wiki/Download)
2014-07-15 16:52:17 +00:00
Project structure
-----------------
2015-01-30 21:05:50 +00:00
First you need to setup the project structure:
2014-07-15 16:52:17 +00:00
export GOPATH=$HOME/gocodez
mkdir -p $GOPATH/src/github.com/influxdb
cd $GOPATH/src/github.com/influxdb
git clone git@github.com:influxdb/influxdb
2014-07-17 16:49:45 +00:00
You can add the line `export GOPATH=$HOME/gocodez` to your bash/zsh
file to be set for every shell instead of having to manually run it
everytime.
2014-07-15 16:52:17 +00:00
We have a pre commit hook to make sure code is formatted properly
and vetted before you commit any changes. We strongly recommend using the pre
2014-07-15 16:52:17 +00:00
commit hook to guard against accidentally committing unformatted
code. To use the pre-commit hook, run the following:
cd $GOPATH/src/github.com/influxdb/influxdb
2014-07-15 17:00:21 +00:00
cp .hooks/pre-commit .git/hooks/
2014-07-15 16:52:17 +00:00
2014-07-15 16:55:38 +00:00
In case the commit is rejected because it's not formatted you can run
the following to format the code:
```
go fmt ./...
go vet ./...
```
To install go vet, run the following command:
```
go get golang.org/x/tools/cmd/vet
```
2015-02-13 21:41:19 +00:00
NOTE: If you have not installed mercurial, the above command will fail. See [Revision Control Systems](#revision-control-systems) above.
For more information on `go vet`, [read the GoDoc](https://godoc.org/golang.org/x/tools/cmd/vet).
2014-11-18 23:58:26 +00:00
Build and Test
2014-11-18 21:58:11 +00:00
-----
2014-07-15 16:55:38 +00:00
2015-01-30 21:05:50 +00:00
Make sure you have Go installed and the project structure as shown above. To then build the project, execute the following commands:
2014-07-17 16:49:45 +00:00
2014-11-18 21:58:11 +00:00
```bash
2014-11-18 23:58:26 +00:00
cd $GOPATH/src/github.com/influxdb
go get -u -f ./...
2014-11-18 23:58:26 +00:00
go build ./...
```
Once compilation completes, the binaries can be found in `$GOPATH/bin`. Please note that the InfluxDB binary is named `influxd`, not `influxdb`.
To set the version and commit flags during the build pass the following to the build command:
```bash
-ldflags="-X main.version $VERSION -X main.commit $COMMIT"
```
where $VERSION is the version, and $COMMIT is the git commit hash.
2014-11-18 23:58:26 +00:00
2014-11-19 19:38:13 +00:00
To run the tests, execute the following command:
2014-11-18 23:58:26 +00:00
```bash
2014-11-19 19:38:13 +00:00
cd $GOPATH/src/github.com/influxdb/influxdb
go test -v ./...
2014-07-15 16:52:17 +00:00
2014-11-18 23:58:26 +00:00
# run tests that match some pattern
2014-11-18 21:58:11 +00:00
go test -run=TestDatabase . -v
2014-07-15 16:52:17 +00:00
2014-11-18 21:58:11 +00:00
# run tests and show coverage
go test -coverprofile /tmp/cover . && go tool cover -html /tmp/cover
```
2014-07-17 16:36:01 +00:00
2015-02-17 19:35:11 +00:00
To install go cover, run the following command:
```
go get golang.org/x/tools/cmd/cover
```
2014-07-17 16:36:01 +00:00
Useful links
------------
- [Useful techniques in Go](http://arslan.io/ten-useful-techniques-in-go)
- [Go in production](http://peter.bourgon.org/go-in-production/)
- [Principles of designing Go APIs with channels](https://inconshreveable.com/07-08-2014/principles-of-designing-go-apis-with-channels/)
- [Common mistakes in Golang](http://soryy.com/blog/2014/common-mistakes-with-go-lang/). Especially this section `Loops, Closures, and Local Variables`