Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

## Setup your machine

`example` is written in [Go](https://golang.org/).
`optional` is written in [Go](https://golang.org/).

Prerequisites are:

* Build:
* `make`
* [Go 1.8+](http://golang.org/doc/install)
* [Go 1.10+](http://golang.org/doc/install)

Clone `example` from source into `$GOPATH`:
Clone `optional` from source into `$GOPATH`:

```sh
$ go get github.com/markphelps/example
$ cd $GOPATH/src/github.com/markphelps/example
$ go get github.com/markphelps/optional
$ cd $GOPATH/src/github.com/markphelps/optional
```

Install the build and lint dependencies:
Expand Down Expand Up @@ -47,5 +47,5 @@ Which runs all the linters and tests.

## Submit a pull request

Push your branch to your `example` fork and open a pull request against the
Push your branch to your `optional` fork and open a pull request against the
master branch.
24 changes: 14 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
GOTOOLS = \
github.com/golang/dep/cmd/dep \
github.com/golangci/golangci-lint/cmd/golangci-lint \
golang.org/x/tools/cmd/cover \

SOURCE_FILES?=./...
TEST_PATTERN?=.
TEST_OPTIONS?=

.PHONY: setup
setup: ## Install all the build and lint dependencies
@echo "--> Installing tools"
@go get -u $(GOTOOLS)
go get -u $(GOTOOLS)

.PHONY: dep
dep: ## Install all import dependencies
@echo "--> Installing dependencies"
@dep ensure
dep ensure

.PHONY: test
test: ## Run all the tests
@echo "--> Running tests"
@echo 'mode: atomic' > coverage.txt && go list ./... | grep -v /vendor/ | xargs -n1 -I{} sh -c 'go test -covermode=atomic -coverprofile=coverage.txt -v -race -timeout=30s {}'
go test $(TEST_OPTIONS) -failfast $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=1m

.PHONY: cover
cover: test ## Run all the tests and opens the coverage report
go tool cover -html=coverage.txt
.PHONY: golden
golden: ## Updates goldenfiles and runs tests
@echo "--> Updating goldenfiles"
go test ./cmd/optional/... -update

.PHONY: fmt
fmt: ## gofmt and goimports all go files
Expand All @@ -30,20 +34,20 @@ fmt: ## gofmt and goimports all go files
.PHONY: lint
lint: ## Run all the linters
@echo "--> Running linters"
@golangci-lint run
golangci-lint run

.PHONY: ci
ci: lint test ## Run all the tests and code checks

.PHONY: generate
generate: ## Run go generate
@echo "--> Running go generate"
@go generate
go generate

.PHONY: build
build: ## Build
@echo "--> Building ..."
@go build -o bin/optional ./cmd/optional/main.go
go build -o bin/optional ./cmd/optional/main.go

# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
Expand Down
10 changes: 9 additions & 1 deletion bool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion byte.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cmd/optional/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ func ({{ .VariableName }} {{ .OutputName }}) Get() ({{ .TypeName }}, error) {
return *{{ .VariableName }}.value, nil
}

// Must returns the {{ .TypeName }} value or panics if not present.
func ({{ .VariableName }} {{ .OutputName }}) Must() {{ .TypeName }} {
if !{{ .VariableName }}.Present() {
panic("value not present")
}
return *{{ .VariableName }}.value
}

// Present returns whether or not the value is present.
func ({{ .VariableName }} {{ .OutputName }}) Present() bool {
return {{ .VariableName }}.value != nil
Expand Down
10 changes: 9 additions & 1 deletion cmd/optional/testdata/optional_bar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion cmd/optional/testdata/optional_foo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion cmd/optional/testdata/string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion complex128.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion complex64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion float32.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion float64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion int.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion int16.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion int32.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading