diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 2a412e3..34cc1b7 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -14,26 +14,26 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v1 - - name: Download golangci-lint command - run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.21.0 - - name: Lint Go Code - run: PATH=$PATH:$(go env GOPATH)/bin golangci-lint run ./... + uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.28.3 test: name: Test runs-on: ubuntu-latest strategy: matrix: - go: [ '1.13.x', '1.14.x', '1.15.x' ] + go: [ '1.14.x', '1.15.x' ] steps: + - name: Check out code + uses: actions/checkout@v2 - name: Set up Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v2 with: go-version: ${{ matrix.go }} - - name: Check out code - uses: actions/checkout@v1 - name: Test Go Code - run: PATH=$PATH:$(go env GOPATH)/bin go test -covermode=atomic -coverprofile=coverage.txt ./... + run: go test -covermode=atomic -coverprofile=coverage.txt ./... - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 with: diff --git a/.golangci.yml b/.golangci.yml index 1e2a1d1..af8d43d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,3 +10,5 @@ linters: disable: - whitespace - wsl + - goerr113 + - funlen diff --git a/base58/base58.go b/base58/base58.go index 4f9ab3b..1cbb166 100644 --- a/base58/base58.go +++ b/base58/base58.go @@ -8,9 +8,11 @@ import ( "errors" ) +const characters = 58 + // An Encoder implements indigo.Encoder interface by Base58. type Encoder struct { - encode [58]byte + encode [characters]byte decodeMap [256]int } @@ -30,8 +32,7 @@ func MustNewEncoder(source string) *Encoder { // NewEncoder returns new base58.Encoder. func NewEncoder(source string) (*Encoder, error) { - - if len(source) != 58 { + if len(source) != characters { return nil, errors.New("base58: encoding source is not 58-bytes long") } @@ -51,7 +52,6 @@ func NewEncoder(source string) (*Encoder, error) { // Encode returns encoded string by Base58. func (enc *Encoder) Encode(id uint64) string { - if id == 0 { return string(enc.encode[:1]) } @@ -59,7 +59,7 @@ func (enc *Encoder) Encode(id uint64) string { bin := make([]byte, 0, binary.MaxVarintLen64) for id > 0 { bin = append(bin, enc.encode[id%58]) - id /= 58 + id /= characters } for i, j := 0, len(bin)-1; i < j; i, j = i+1, j-1 { @@ -71,7 +71,6 @@ func (enc *Encoder) Encode(id uint64) string { // Decode returns decoded unsigned int64 by Base58. func (enc *Encoder) Decode(id string) (uint64, error) { - if id == "" { return 0, errors.New("base58: id should not be empty") } @@ -82,7 +81,7 @@ func (enc *Encoder) Decode(id string) (uint64, error) { if u < 0 { return 0, errors.New("base58: invalid character - " + string(id[i])) } - n = n*58 + uint64(u) + n = n*characters + uint64(u) } return n, nil diff --git a/base58/base58_test.go b/base58/base58_test.go index 8524643..35e16a7 100644 --- a/base58/base58_test.go +++ b/base58/base58_test.go @@ -17,7 +17,6 @@ func TestStdSource(t *testing.T) { } func TestMustNewEncoder(t *testing.T) { - enc := base58.MustNewEncoder("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") if enc == nil { t.Error("should not be nil") @@ -25,7 +24,9 @@ func TestMustNewEncoder(t *testing.T) { func() { defer func() { - recover() + if err := recover(); err == nil { + t.Error("should not be nil") + } }() base58.MustNewEncoder("") t.Error("should be panic") @@ -33,7 +34,9 @@ func TestMustNewEncoder(t *testing.T) { func() { defer func() { - recover() + if err := recover(); err == nil { + t.Error("should not be nil") + } }() base58.MustNewEncoder("test") t.Error("should be panic") @@ -41,7 +44,6 @@ func TestMustNewEncoder(t *testing.T) { } func TestNewEncoder(t *testing.T) { - enc, err := base58.NewEncoder("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") if err != nil { t.Error("should be nil") @@ -62,7 +64,6 @@ func TestNewEncoder(t *testing.T) { } func TestEncoder_Encode(t *testing.T) { - bc := map[uint64]string{ 0: "1", 57: "z", @@ -86,7 +87,6 @@ func TestEncoder_Encode(t *testing.T) { } func TestEncoder_Decode(t *testing.T) { - bc := map[uint64]string{ 0: "1", 57: "z", @@ -119,7 +119,6 @@ func TestEncoder_Decode(t *testing.T) { } func BenchmarkEncoder_Encode(b *testing.B) { - s := rand.New(rand.NewSource(time.Now().UnixNano())) enc := base58.MustNewEncoder(base58.StdSource()) @@ -131,7 +130,6 @@ func BenchmarkEncoder_Encode(b *testing.B) { } func BenchmarkEncoder_Decode(b *testing.B) { - bc := map[uint64]string{ 0: "1", 57: "z", diff --git a/indigo_test.go b/indigo_test.go index f2ee5d6..e7c3d9c 100644 --- a/indigo_test.go +++ b/indigo_test.go @@ -27,7 +27,6 @@ func TestNew(t *testing.T) { } func TestGenerator_NextID(t *testing.T) { - g := indigo.New( nil, indigo.StartTime(time.Unix(1257894000, 0)), @@ -58,7 +57,6 @@ func TestGenerator_NextID(t *testing.T) { } func TestGenerator_Decompose(t *testing.T) { - g := indigo.New( nil, indigo.StartTime(time.Unix(1257894000, 0)), @@ -84,7 +82,6 @@ func TestGenerator_Decompose(t *testing.T) { } func TestGenerator_NextID_Race(t *testing.T) { - g := indigo.New( nil, indigo.StartTime(time.Unix(1257894000, 0)), @@ -113,7 +110,6 @@ func TestGenerator_NextID_Race(t *testing.T) { } func TestGenerator_NextID_SortIDs(t *testing.T) { - th := 10 ids := make([]string, 0, 100) @@ -182,7 +178,6 @@ func TestGenerator_NextID_SortIDs(t *testing.T) { } func BenchmarkGenerator_NextID(b *testing.B) { - g := indigo.New( nil, indigo.StartTime(time.Now()),