Skip to content

Commit d28f003

Browse files
committed
Initial Open Source release of can-go
1 parent aff2c1f commit d28f003

File tree

155 files changed

+17287
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+17287
-0
lines changed

.circleci/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/golang:1.13-stretch-node
6+
steps:
7+
- checkout
8+
- run: make

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
.gobincache
3+
build/files

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Einride AB
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
all: \
2+
go-stringer \
3+
go-mock-gen \
4+
testdata \
5+
go-lint \
6+
go-test \
7+
go-mod-tidy \
8+
git-verify-nodiff
9+
10+
include build/rules.mk
11+
12+
.PHONY: clean
13+
clean:
14+
rm -rf $(FILES_DIR)
15+
16+
.PHONY: go-lint
17+
go-lint: $(GOLANGCI_LINT)
18+
# funlen: too strict
19+
# dupl: allow duplication in tests
20+
# interfacer: deprecated
21+
# godox: allow TODOs
22+
# lll: long go:generate directives
23+
$(GOLANGCI_LINT) run --enable-all --disable funlen,dupl,interfacer,godox,lll
24+
25+
.PHONY: go-mock-gen
26+
go-mock-gen: \
27+
internal/mocks/mockcanrunner/mocks.go \
28+
internal/mocks/mockclock/mocks.go \
29+
internal/mocks/mocksocketcan/mocks.go
30+
31+
internal/mocks/mockcanrunner/mocks.go: pkg/canrunner/run.go $(GOBIN)
32+
$(GOBIN) -m -run github.com/golang/mock/mockgen -destination $@ \
33+
-package mockcanrunner go.einride.tech/can/pkg/canrunner \
34+
Node,TransmittedMessage,ReceivedMessage,FrameTransmitter,FrameReceiver
35+
36+
internal/mocks/mockclock/mocks.go: internal/clock/clock.go $(GOBIN)
37+
$(GOBIN) -m -run github.com/golang/mock/mockgen -destination $@ \
38+
-package mockclock go.einride.tech/can/internal/clock \
39+
Clock,Ticker
40+
41+
internal/mocks/mocksocketcan/mocks.go: pkg/socketcan/fileconn.go $(GOBIN)
42+
$(GOBIN) -m -run github.com/golang/mock/mockgen -destination $@ \
43+
-package mocksocketcan -source $<
44+
45+
.PHONY: go-stringer
46+
go-stringer: \
47+
pkg/descriptor/sendtype_string.go \
48+
pkg/socketcan/errorclass_string.go \
49+
pkg/socketcan/protocolviolationerrorlocation_string.go \
50+
pkg/socketcan/protocolviolationerror_string.go \
51+
pkg/socketcan/controllererror_string.go \
52+
pkg/socketcan/transceivererror_string.go
53+
54+
%_string.go: %.go
55+
go generate $<
56+
57+
.PHONY: testdata
58+
testdata:
59+
go run cmd/cantool/main.go generate testdata/dbc testdata/gen/go
60+
61+
.PHONY: go-test
62+
go-test:
63+
go test -race -cover ./...
64+
65+
.PHONY: go-mod-tidy
66+
go-mod-tidy:
67+
go mod tidy -v

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# :electric_plug: CAN Go [![GoDoc][doc-img]][doc]
2+
3+
CAN toolkit for Go programmers.
4+
5+
[doc-img]: https://godoc.org/go.einride.tech/can?status.svg
6+
[doc]: https://godoc.org/go.einride.tech/can

build/git.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: git-verify-nodiff
2+
git-verify-nodiff:
3+
@$(BUILD_DIR)/scripts/git-verify-nodiff.sh

build/go.mk

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
GOLANGCI_LINT_VERSION := 1.19.1
2+
GOLANGCI_LINT := $(FILES_DIR)/golangci-lint/$(GOLANGCI_LINT_VERSION)/golangci-lint
3+
4+
GOBIN_VERSION := 0.0.13
5+
GOBIN := $(FILES_DIR)/gobin/$(GOBIN_VERSION)/gobin
6+
export PATH := $(dir $(GOBIN)):$(PATH)
7+
8+
$(GOLANGCI_LINT):
9+
mkdir -p $(dir $@)
10+
curl -s -L -o $(dir $(GOLANGCI_LINT))/archive.tar.gz \
11+
https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_LINT_VERSION)/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(UNAME)-amd64.tar.gz
12+
tar xzf $(dir $(GOLANGCI_LINT))/archive.tar.gz -C $(dir $(GOLANGCI_LINT)) --strip 1
13+
chmod +x $@
14+
touch $@
15+
16+
$(GOBIN):
17+
mkdir -p $(dir $@)
18+
curl -s -L -o $@ \
19+
https://github.com/myitcv/gobin/releases/download/v$(GOBIN_VERSION)/$(UNAME)-amd64
20+
chmod +x $@
21+
touch $@

build/rules.mk

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
SHELL := /bin/bash
2+
3+
BUILD_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
4+
FILES_DIR := $(BUILD_DIR)/files
5+
6+
UNAME := $(shell uname -s)
7+
UNAME_LOWERCASE := $(shell uname -s | tr '[:upper:]' '[:lower:]')
8+
9+
ifeq ($(UNAME),Linux)
10+
else ifeq ($(UNAME),Darwin)
11+
else
12+
$(error This Makefile only supports Linux and OSX build agents.)
13+
endif
14+
15+
ifneq ($(shell uname -m),x86_64)
16+
$(error This Makefile only supports x86_64 build agents.)
17+
endif
18+
19+
ifneq ($(shell which curl >/dev/null; echo $$?),0)
20+
$(error cURL not installed. This Makefile requires cURL.)
21+
endif
22+
23+
ifneq ($(shell which realpath >/dev/null; echo $$?),0)
24+
$(error Coreutils not installed. OSX users run: brew install coreutils)
25+
endif
26+
27+
include $(BUILD_DIR)/git.mk
28+
include $(BUILD_DIR)/go.mk

build/scripts/git-verify-nodiff.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
if [[ ! -z $(git status --porcelain) ]]; then
6+
echo "Staging area is dirty, please add all files created by the build to .gitignore"
7+
git status -s
8+
exit 1
9+
fi

can.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Package can provides primitives for working with CAN.
2+
//
3+
// See: https://en.wikipedia.org/wiki/CAN_bus
4+
package can // import "go.einride.tech/can"

0 commit comments

Comments
 (0)