Skip to content

Commit

Permalink
Bring up to date - switch to Go modules, add GitHub actions etc. (#9)
Browse files Browse the repository at this point in the history
* Bring up to date - switch to Go modules, add GitHub actions etc.

* Add -race flag to test
  • Loading branch information
liamg authored Jul 28, 2023
1 parent 9a90189 commit e2b75d5
Show file tree
Hide file tree
Showing 72 changed files with 73 additions and 13,125 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint
on:
pull_request:
jobs:
build:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- run: make lint
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test
on:
pull_request:
jobs:
build:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- run: make test

5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

74 changes: 0 additions & 74 deletions Gopkg.lock

This file was deleted.

38 changes: 0 additions & 38 deletions Gopkg.toml

This file was deleted.

21 changes: 8 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
default : vet test build
golangcilint_version := "1.53.3"

.PHONY: build
build:
go build
default : lint test

.PHONY: vet
vet:
go vet ./...
.PHONY: lint
lint:
@echo "Linting..."
@(which golangci-lint && [[ "$$(golangci-lint --version | awk '{print $$4}')" == "$(golangcilint_version)" ]] ) || go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(golangcilint_version)
@golangci-lint run

.PHONY: test
test:
go test -v ./...

.PHONY: release
release:
go get github.com/goreleaser/goreleaser;
goreleaser;
go test -race ./...
16 changes: 16 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module github.com/liamg/magic

go 1.20

require (
github.com/stretchr/testify v1.8.4
gotest.tools v2.2.0+incompatible
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
2 changes: 1 addition & 1 deletion magic.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func LookupSync(bytes []byte) (*FileType, error) {
func lookup(bytes []byte, concurrent bool, workers int) (*FileType, error) {
// additional worker count check: avoid deadlock when worker count is set to zero
if !concurrent || workers == 0 {
for _, t := range types {
for _, t := range Types {
ft := t.check(bytes, 0)
if ft != nil {
return ft, nil
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (ft *FileType) check(data []byte, offset int) *FileType {
if len(trunc) < len(ft.Magic) {
return nil
}
if bytes.Compare(trunc[:len(ft.Magic)], ft.Magic) == 0 {
if bytes.Equal(trunc[:len(ft.Magic)], ft.Magic) {
if ft.children == nil {
return ft
}
Expand Down
15 changes: 0 additions & 15 deletions vendor/github.com/davecgh/go-spew/LICENSE

This file was deleted.

145 changes: 0 additions & 145 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

This file was deleted.

Loading

0 comments on commit e2b75d5

Please sign in to comment.