-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial state of examples. Signed-off-by: bwplotka <bwplotka@gmail.com> * More examples from book. Signed-off-by: bwplotka <bwplotka@gmail.com> Signed-off-by: bwplotka <bwplotka@gmail.com>
- Loading branch information
Showing
97 changed files
with
7,684 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
# Ignore everything | ||
* | ||
|
||
# But not these files: | ||
!.gitignore | ||
!*.mod | ||
!README.md | ||
!Variables.mk | ||
!variables.env | ||
|
||
*tmp.mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Project Development Dependencies. | ||
|
||
This is directory which stores Go modules with pinned buildable package that is used within this repository, managed by https://github.com/bwplotka/bingo. | ||
|
||
* Run `bingo get` to install all tools having each own module file in this directory. | ||
* Run `bingo get <tool>` to install <tool> that have own module file in this directory. | ||
* For Makefile: Make sure to put `include .bingo/Variables.mk` in your Makefile, then use $(<upper case tool name>) variable where <tool> is the .bingo/<tool>.mod. | ||
* For shell: Run `source .bingo/variables.env` to source all environment variable for each tool. | ||
* For go: Import `.bingo/variables.go` to for variable names. | ||
* See https://github.com/bwplotka/bingo or -h on how to add, remove or change binaries dependencies. | ||
|
||
## Requirements | ||
|
||
* Go 1.14+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.4.3. DO NOT EDIT. | ||
# All tools are designed to be build inside $GOBIN. | ||
BINGO_DIR := $(dir $(lastword $(MAKEFILE_LIST))) | ||
GOPATH ?= $(shell go env GOPATH) | ||
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin | ||
GO ?= $(shell which go) | ||
|
||
# Below generated variables ensure that every time a tool under each variable is invoked, the correct version | ||
# will be used; reinstalling only if needed. | ||
# For example for copyright variable: | ||
# | ||
# In your main Makefile (for non array binaries): | ||
# | ||
#include .bingo/Variables.mk # Assuming -dir was set to .bingo . | ||
# | ||
#command: $(COPYRIGHT) | ||
# @echo "Running copyright" | ||
# @$(COPYRIGHT) <flags/args..> | ||
# | ||
COPYRIGHT := $(GOBIN)/copyright-v0.0.0-20210829154005-c7bad8450208 | ||
$(COPYRIGHT): $(BINGO_DIR)/copyright.mod | ||
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. | ||
@echo "(re)installing $(GOBIN)/copyright-v0.0.0-20210829154005-c7bad8450208" | ||
@cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=copyright.mod -o=$(GOBIN)/copyright-v0.0.0-20210829154005-c7bad8450208 "github.com/efficientgo/tools/copyright" | ||
|
||
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.42.0 | ||
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod | ||
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies. | ||
@echo "(re)installing $(GOBIN)/golangci-lint-v1.42.0" | ||
@cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.42.0 "github.com/golangci/golangci-lint/cmd/golangci-lint" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT | ||
|
||
go 1.17 | ||
|
||
require github.com/efficientgo/tools/copyright v0.0.0-20210829154005-c7bad8450208 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT | ||
|
||
go 1.17 | ||
|
||
require github.com/golangci/golangci-lint v1.42.0 // cmd/golangci-lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.4.3. DO NOT EDIT. | ||
# All tools are designed to be build inside $GOBIN. | ||
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk. | ||
GOBIN=${GOBIN:=$(go env GOBIN)} | ||
|
||
if [ -z "$GOBIN" ]; then | ||
GOBIN="$(go env GOPATH)/bin" | ||
fi | ||
|
||
|
||
COPYRIGHT="${GOBIN}/copyright-v0.0.0-20210829154005-c7bad8450208" | ||
|
||
GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.42.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export GOPATH=~/Repos/sharedgopath | ||
export GOBIN=~/Repos/examples/.bin | ||
export PATH=${PATH}:${GOBIN} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: go | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
pull_request: | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
name: Linters (Static Analysis) for Go | ||
steps: | ||
- name: Checkout code into the Go module directory. | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18.x | ||
|
||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
|
||
- name: Linting & vetting. | ||
env: | ||
GOBIN: /tmp/.bin | ||
run: make lint | ||
tests: | ||
runs-on: ${{ matrix.platform }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
go: ["1.18.x", "1.19.x"] | ||
platform: [ubuntu-latest, macos-latest] | ||
|
||
name: Unit tests on Go ${{ matrix.go }} ${{ matrix.platform }} | ||
steps: | ||
- name: Checkout code into the Go module directory. | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: Install docker - MacOS | ||
if: runner.os == 'macOS' | ||
run: | | ||
brew install docker colima | ||
colima start | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
|
||
- name: Run unit tests. | ||
env: | ||
GOBIN: /tmp/.bin | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Copyright (c) Efficient Go Authors | ||
Licensed under the Apache License 2.0. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
include .bingo/Variables.mk | ||
|
||
MODULES ?= $(shell find $(PWD) -name "go.mod" | grep -v ".bingo" | xargs dirname) | ||
|
||
GO111MODULE ?= on | ||
export GO111MODULE | ||
|
||
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin | ||
|
||
# Tools. | ||
GIT ?= $(shell which git) | ||
|
||
# Support gsed on OSX (installed via brew), falling back to sed. On Linux | ||
# systems gsed won't be installed, so will use sed as expected. | ||
SED ?= $(shell which gsed 2>/dev/null || which sed) | ||
|
||
define require_clean_work_tree | ||
@git update-index -q --ignore-submodules --refresh | ||
|
||
@if ! git diff-files --quiet --ignore-submodules --; then \ | ||
echo >&2 "$1: you have unstaged changes."; \ | ||
git diff-files --name-status -r --ignore-submodules -- >&2; \ | ||
echo >&2 "Please commit or stash them."; \ | ||
exit 1; \ | ||
fi | ||
|
||
@if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then \ | ||
echo >&2 "$1: your index contains uncommitted changes."; \ | ||
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2; \ | ||
echo >&2 "Please commit or stash them."; \ | ||
exit 1; \ | ||
fi | ||
|
||
endef | ||
|
||
help: ## Displays help. | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) | ||
|
||
.PHONY: all | ||
all: format | ||
|
||
.PHONY: deps | ||
deps: ## Cleans up deps for all modules | ||
@echo ">> running deps tidy for all modules: $(MODULES)" | ||
for dir in $(MODULES) ; do \ | ||
cd $${dir} && go mod tidy; \ | ||
done | ||
|
||
.PHONY: docs | ||
docs: $(MDOX) ## Generates config snippets and doc formatting. | ||
@echo ">> generating docs $(PATH)" | ||
@$(MDOX) fmt *.md | ||
|
||
.PHONY: docker | ||
docker: | ||
@echo ">> building labeler docker file" | ||
@cd ./pkg/sum/labeler && CGO_ENABLED=0 GOOS=linux go build -o labeler . | ||
@cd ./pkg/sum/labeler && docker build -t labeler:test . | ||
|
||
.PHONY: format | ||
format: ## Formats Go code. | ||
format: $(GOIMPORTS) | ||
@echo ">> formatting all modules Go code: $(MODULES)" | ||
@$(GOIMPORTS) -w $(MODULES) | ||
|
||
.PHONY: test | ||
test: ## Runs all Go unit tests. | ||
@echo ">> running tests for all modules: $(MODULES)" | ||
for dir in $(MODULES) ; do \ | ||
cd $${dir} && go test -v -race ./...; \ | ||
done | ||
|
||
.PHONY: check-git | ||
check-git: | ||
ifneq ($(GIT),) | ||
@test -x $(GIT) || (echo >&2 "No git executable binary found at $(GIT)."; exit 1) | ||
else | ||
@echo >&2 "No git binary found."; exit 1 | ||
endif | ||
|
||
# PROTIP: | ||
# Add | ||
# --cpu-profile-path string Path to CPU profile output file | ||
# --mem-profile-path string Path to memory profile output file | ||
# to debug big allocations during linting. | ||
lint: ## Runs various static analysis against our code. | ||
lint: $(GOLANGCI_LINT) $(COPYRIGHT) format docs check-git deps | ||
$(call require_clean_work_tree,"detected not clean master before running lint - run make lint and commit changes.") | ||
@echo ">> examining all of the Go files" | ||
for dir in $(MODULES) ; do \ | ||
cd $${dir} && go vet -stdmethods=false ./...; \ | ||
done | ||
@echo ">> linting all of the Go files GOGC=${GOGC}" | ||
for dir in $(MODULES) ; do \ | ||
cd $${dir} && $(GOLANGCI_LINT) run; \ | ||
done | ||
@echo ">> ensuring Copyright headers" | ||
@$(COPYRIGHT) $(shell go list -f "{{.Dir}}" ./... | xargs -i find "{}" -name "*.go") | ||
$(call require_clean_work_tree,"detected files without copyright - run make lint and commit changes.") |
Oops, something went wrong.