Skip to content

Commit

Permalink
Fix warnings by golang-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
osamingo committed Jan 15, 2021
1 parent 8cdf3b8 commit bb06a68
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ linters:
disable:
- whitespace
- wsl
- goerr113
- funlen
13 changes: 6 additions & 7 deletions base58/base58.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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")
}

Expand All @@ -51,15 +52,14 @@ 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])
}

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 {
Expand All @@ -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")
}
Expand All @@ -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
Expand Down
14 changes: 6 additions & 8 deletions base58/base58_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,33 @@ func TestStdSource(t *testing.T) {
}

func TestMustNewEncoder(t *testing.T) {

enc := base58.MustNewEncoder("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz")
if enc == nil {
t.Error("should not be nil")
}

func() {
defer func() {
recover()
if err := recover(); err == nil {
t.Error("should not be nil")
}
}()
base58.MustNewEncoder("")
t.Error("should be panic")
}()

func() {
defer func() {
recover()
if err := recover(); err == nil {
t.Error("should not be nil")
}
}()
base58.MustNewEncoder("test")
t.Error("should be panic")
}()
}

func TestNewEncoder(t *testing.T) {

enc, err := base58.NewEncoder("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz")
if err != nil {
t.Error("should be nil")
Expand All @@ -62,7 +64,6 @@ func TestNewEncoder(t *testing.T) {
}

func TestEncoder_Encode(t *testing.T) {

bc := map[uint64]string{
0: "1",
57: "z",
Expand All @@ -86,7 +87,6 @@ func TestEncoder_Encode(t *testing.T) {
}

func TestEncoder_Decode(t *testing.T) {

bc := map[uint64]string{
0: "1",
57: "z",
Expand Down Expand Up @@ -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())

Expand All @@ -131,7 +130,6 @@ func BenchmarkEncoder_Encode(b *testing.B) {
}

func BenchmarkEncoder_Decode(b *testing.B) {

bc := map[uint64]string{
0: "1",
57: "z",
Expand Down
5 changes: 0 additions & 5 deletions indigo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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)),
Expand All @@ -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)),
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()),
Expand Down

0 comments on commit bb06a68

Please sign in to comment.