Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor beginning #111

Merged
merged 64 commits into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
75d3e6e
add proto Makefile command
bufdev Dec 21, 2015
8071787
add enum definitions to api.proto
bufdev Dec 21, 2015
4fd55f1
add message definitions to api.proto, remove unused types in cluster.go
bufdev Dec 21, 2015
493b751
comment on FSType
bufdev Dec 21, 2015
92b14f4
ClusterStatus to Status
bufdev Dec 21, 2015
c06e826
*** remove most api public types, add generated protobuf definitions ***
bufdev Dec 21, 2015
140a445
api/client, cluster, volume compiling
bufdev Dec 21, 2015
d0ceb68
start fixing api/server errors
bufdev Dec 21, 2015
2faf10e
restBase.logReq to restBase.logRequest
bufdev Dec 21, 2015
0110e54
clean up cluster init and start logic
bufdev Dec 21, 2015
50d94f0
simple strings and simple value of functions, cleanup for cluster api
bufdev Dec 21, 2015
56f91ae
api/server builds but needs cleanup
bufdev Dec 21, 2015
5d47ee7
graph package updated
bufdev Dec 21, 2015
091263a
start getting volume drivers to compile, volume/drivers/aws compiling
bufdev Dec 21, 2015
0ccc067
start getting volume/drivers/btrfs cleaned up
bufdev Dec 21, 2015
b533dff
volume/drivers/btrfs compiling
bufdev Dec 21, 2015
c043477
add volume/drivers/common/common.go
bufdev Dec 21, 2015
be79eb1
add volume/drivers/common/common.go
bufdev Dec 21, 2015
c8bfc85
start working on volume/drivers/buse
bufdev Dec 21, 2015
ce1d361
merge
bufdev Dec 21, 2015
1e28d9f
merge
bufdev Jan 3, 2016
225de84
add protoeasy.yaml
bufdev Jan 3, 2016
0d81bf9
fix pkg/stats
bufdev Jan 3, 2016
a3f12e8
some cleanup for ./volume
bufdev Jan 3, 2016
c4e5cbd
fix aws, btrfs, buse
bufdev Jan 3, 2016
1f92720
use common.NewVolume in buse
bufdev Jan 3, 2016
27d9bfc
fix fise
bufdev Jan 3, 2016
477caf5
fix nfs
bufdev Jan 3, 2016
5fd0d4e
fix pwx
bufdev Jan 3, 2016
c3dc073
fix volume/drivers/test
bufdev Jan 3, 2016
b3575e7
volume building
bufdev Jan 3, 2016
bfeba02
api, cluster, config, pkg, volume building
bufdev Jan 3, 2016
b32e579
cli building
bufdev Jan 3, 2016
98e07b4
make build passing
bufdev Jan 3, 2016
c9607a7
add github.com/golang/protobuf and go.pedge.io/google-protobuf, go.pe…
bufdev Jan 3, 2016
5c7374e
start fixing tests
bufdev Jan 3, 2016
386f2c1
clean up api/client
bufdev Jan 3, 2016
ff6b325
change assert to require in volume/drivers/test/driver.go
bufdev Jan 3, 2016
19abd94
remove logrus debug print of body in client
bufdev Jan 3, 2016
4654abe
Merge branch 'master' into refactor
bufdev Jan 3, 2016
ec085f8
remove volume action ignore
bufdev Jan 3, 2016
88c7117
fix api/client testing
bufdev Jan 3, 2016
68e6951
change make docker-build to make docker-build-osd-dev, add make docke…
bufdev Jan 3, 2016
1f1f7c3
Merge branch 'master' into refactor
jvinod Jan 16, 2016
be6ff53
refactor coprhd
jvinod Jan 16, 2016
60bf217
cmdMarshalProto
bufdev Jan 18, 2016
292b91f
add jsonpb to vendor
bufdev Jan 18, 2016
7b13b45
merge
bufdev Jan 21, 2016
1e749d5
fix cluster
bufdev Jan 21, 2016
959dd36
proto outputs json etc
bufdev Jan 21, 2016
eda632c
fix volume cos for cli command
bufdev Jan 22, 2016
7b33657
COS back to int, and update vendor
bufdev Jan 22, 2016
a858113
custom jsonpb for cli output
bufdev Jan 22, 2016
27f8ccb
add diff
bufdev Jan 22, 2016
fa57fcf
style guide
bufdev Jan 22, 2016
f0e0502
Update STYLEGUIDE.md
bufdev Jan 22, 2016
467ab17
make config package not depend on other openstorage code, centralize …
bufdev Jan 22, 2016
2a41b1b
delete protoeasy.yaml
bufdev Jan 22, 2016
e073738
readme for protoeasy
bufdev Jan 22, 2016
86471b3
move from logrus to dlog
bufdev Jan 22, 2016
89eec9f
move to dlog register functions from dlog blank imports
bufdev Jan 22, 2016
3201922
make json timestamps readable
bufdev Jan 25, 2016
fbc67d2
Update STYLEGUIDE.md
gourao Jan 29, 2016
502ca77
merge from master
jvinod Feb 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
33 changes: 29 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,20 @@ build:
install:
go install -tags "$(TAGS)" $(PKGS)

proto:
go get -v go.pedge.io/protoeasy/cmd/protoeasy
go get -v go.pedge.io/pkg/cmd/strip-package-comments
protoeasy --exclude vendor --go --go-import-path github.com/libopenstorage/openstorage .
find . -name *\.pb\*\.go | xargs strip-package-comments

lint:
go get -v github.com/golang/lint/golint
$(foreach pkg,$(PKGS),golint $(pkg);)
for file in $$(find . -name '*.go' | grep -v vendor | grep -v '\.pb\.go' | grep -v '\.pb\.gw\.go'); do \
golint $${file}; \
if [ -n "$$(golint $${file})" ]; then \
exit 1; \
fi; \
done

vet:
go vet $(PKGS)
Expand All @@ -61,10 +72,22 @@ pretest: lint vet errcheck
test:
go test -tags "$(TAGS)" $(TESTFLAGS) $(PKGS)

docker-build:
docker-build-osd-dev:
docker build -t openstorage/osd-dev -f Dockerfile.osd-dev .

docker-test: docker-build
docker-build: docker-build-osd-dev
docker run \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
openstorage/osd-dev \
make build

docker-test: docker-build-osd-dev
docker run \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
Expand All @@ -83,7 +106,7 @@ docker-build-osd-internal:
go build -a -tags "$(TAGS)" -o _tmp/osd cmd/osd/main.go
docker build -t openstorage/osd -f Dockerfile.osd .

docker-build-osd: docker-build
docker-build-osd: docker-build-osd-dev
docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-e "TAGS=$(TAGS)" \
Expand Down Expand Up @@ -113,11 +136,13 @@ clean:
vendor \
build \
install \
proto \
lint \
vet \
errcheck \
pretest \
test \
docker-build-osd-dev \
docker-build \
docker-test \
docker-build-osd-internal \
Expand Down
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,36 @@ WantedBy=multi-user.target
The specification and code is licensed under the Apache 2.0 license found in
the `LICENSE` file of this repository.

See the [Style Guide](STYLEGUIDE.md).

### Protoeasy quick start

https://go.pedge.io/protoeasy

```
docker pull quay.io/pedge/protoeasy
```

Add to your ~/.bashrc (or equivalent):

```
# to use protoeasy for now, you must have docker installed locally or in a vm
# if running docker using docker-machine etc, replace 192.168.10.10 with the ip of the vm
# if running docker locally, replace 192.168.10.10 with 0.0.0.0
export PROTOEASY_ADDRESS=192.168.10.10:6789

launch-protoeasy() {
docker rm -f protoeasy || true
docker run -d -p 6789:6789 --name=protoeasy quay.io/pedge/protoeasy
}
```

Then just run `launch-protoeasy` before compiling the protocol buffers files, and then to compile:

```
make proto
```

### Sign your work

The sign-off is a simple line at the end of the explanation for the
Expand Down Expand Up @@ -296,4 +326,3 @@ then you just add a line to every git commit message:
using your real name (sorry, no pseudonyms or anonymous contributions.)

You can add the sign off when creating the git commit via `git commit -s`.

195 changes: 195 additions & 0 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Style Guide

This is the official openstorage style guide for golang code. This is in addition to the offical style guide at https://github.com/golang/go/wiki/CodeReviewComments.

This is just a rough outline for now, we will formalize this as we go.

IF YOU CODE ON OPENSTORAGE, YOU ARE EXPECTED TO KNOW THIS. Just take the 20 minutes and read through the issues, we will buy you a coffee, maybe.

### Relevant Issues

* https://github.com/libopenstorage/openstorage/issues/100
* https://github.com/libopenstorage/openstorage/issues/88
* https://github.com/libopenstorage/openstorage/issues/97
* https://github.com/libopenstorage/openstorage/issues/87
* https://github.com/libopenstorage/openstorage/issues/92
* https://github.com/libopenstorage/openstorage/issues/89
* https://github.com/libopenstorage/openstorage/issues/76
* https://github.com/libopenstorage/openstorage/issues/71
* https://github.com/libopenstorage/openstorage/issues/96

### Items

* Use [dlog](https://go.pedge.io/dlog) for logging.

* File order:

```go
package pkg

const (
...
)

var (
...
)

// but init should generally be not used
func init() {
}

// public struct

// public struct functions

// private struct functions

// private functions but only if they just apply to this struct, otherwise in a common file
```

* All new code must pass `go vet`, `errcheck`, `golint`. For `errcheck`, this means no more unchecked errors. Use of `_ = someFnThatReturnsError()` will be audited soon, and in general should not be used anymore. `golint` means all public types need comments to pass, which means both (A) we will have better code documentation and (B) we will think more about what should actually be public. `errcheck` and `golint` are great detterrents.

* All packages have a file named `name_of_package.go`, ie in `api/server`, we have `server.go`.

* Packages are named after their directory, ie `api/` is `package api`.

* **ALL PUBLIC TYPES GO IN `name_of_package.go`.** Every other file is just a helper file that implements the types.

* Variable names should reflect the type, ie an instance of `Runner` should be `runner`. This is in contrast to golang's official recommendation, but has been found to make code more readable. Heh. So this means `api.Volume` is not `v, vol, whatever`, it's `volume`, a `request` is not `req, createReq, r`, it's `request`. Only exception is the receiver argument on a function, ie `func (s *server) Foo(...) { ... }`.

* Structs without a corresponding interface are data holders. Structs with functions attached have a public interface wrapper, and then the struct becomes private. Example:

```go
// foo.go
package foo

type Runner interace {
Run(one string, i int) error
}

func NewRunner(something bar.Something) Runner {
return newRunner(something)
}

// runner.go
package foo

type runner struct{
something bar.Something
}

func newRunner(something bar.Something) *runner {
return &runner{something}
}

func (r *runner) Run(one string, i int) error {
r.hello(i)
return r.something.Bar(one, i+1)
}

func (r *runner) hello(i int) {
return r.something.Hello(i)
}
```

* Most structs that have functions attached have a separate file with the private struct definition, private constructor, and public functions, then private functions. The runner struct above is an example.

* Use struct pointers in general instead of structs. It's a debate, but not for now.

* Function parameters/struct initialization/function calls etc are either on one line or each parameter/field has a new line for it. Example:

```go
// yes
function oneLine(a string, b string, c string) {
}

//yes
function multiLine(
a string,
b string,
c string,
) {
}

//no
function multiLineNo(
a string,
b string,
c string) {
}

// no
function multiLineNo2(a string,
b string, c string) {
}
```

* **NO CALLING `os.Exit(...)` OR `panic(...)` IN LIBRARY CODE.** Ie nowhere but a main package.

* New introductions of global variables and init functions have to be vetted extensively by project owners (and existing ones should be deleted as much as we can).

* No reliance on freeform string matching for errors.

* No typing dynamic value primitives. Example:

```go
// no
type VolumeID string

type Volume struct {
VolumeID VolumeID
...
}

//yes
type Volume struct {
VolumeID string
}
```

* Static value primitives (also known as enums) are not strings. Most new ones should be generated with protobuf, see [api/api.proto](api/api.proto) for examples.

* Remove most uses of private variables in public structs.

* Remove most extra variable definitions that are not needed or turn into constants (https://github.com/libopenstorage/openstorage/blob/8d07329468ef709838e443dc17b1eecf2c7cf77d/api/server/volume.go#L76).

* Reduce adding of String() methods on most objects (let the generic `%+v` take care of it).

* Use less newlines within methods.

* Single errors are scoped within an if statement:

```go
// no
err := foo()
if err != nil {
return nil, err
}

// yes
if err := foo(); err != nil {
return nil, err
}

// yes, if ignoring return value
// if _, err := bar(); err != nil {
return nil, err
}
```

* Empty structs:

```go
// no
type EmptyStruct {
}
// yes
type EmptyStruct {}
```

* Blank imports should have explanation (https://github.com/libopenstorage/openstorage/blob/8d07329468ef709838e443dc17b1eecf2c7cf77d/volume/enumerator.go#L6).

* No code checked in that has warnings https://golang.org/cmd/cgo/.

* Do not check in if `make docker-test` does not pass.
Loading