Skip to content

Commit f7e0988

Browse files
committed
[add] Added gofmt automation/check. Added release drafter github action.
1 parent 22e7dd7 commit f7e0988

File tree

8 files changed

+97
-38
lines changed

8 files changed

+97
-38
lines changed

.circleci/config.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ jobs:
1414
working_directory: /go/src/github.com/RedisBloom/redisbloom-go
1515
steps:
1616
- checkout
17-
- run: go get -v -t -d ./...
18-
19-
#run tests with coverage
17+
- run: make checkfmt
2018
- run: make get
2119
- run: make coverage
2220
- run: bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN}

.github/release-drafter-config.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name-template: 'Version $NEXT_PATCH_VERSION - Summary Here🌈'
2+
tag-template: 'v$NEXT_PATCH_VERSION'
3+
categories:
4+
- title: '🚀Features'
5+
labels:
6+
- 'feature'
7+
- 'enhancement'
8+
- title: 'Bug Fixes'
9+
labels:
10+
- 'fix'
11+
- 'bugfix'
12+
- 'bug'
13+
- title: '🧰Maintenance'
14+
label: 'chore'
15+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
16+
exclude-labels:
17+
- 'skip-changelog'
18+
template: |
19+
## Changes
20+
21+
$CHANGES
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
# branches to consider in the event; optional, defaults to all
6+
branches:
7+
- master
8+
9+
jobs:
10+
update_release_draft:
11+
runs-on: ubuntu-latest
12+
steps:
13+
# Drafts your next Release notes as Pull Requests are merged into "master"
14+
- uses: release-drafter/release-drafter@v5
15+
with:
16+
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
17+
config-name: release-drafter-config.yml
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.golangci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# options for analysis running
2+
run:
3+
# include test files or not, default is true
4+
tests: false
5+
6+
linters-settings:
7+
golint:
8+
# minimal confidence for issues, default is 0.8
9+
min-confidence: 0.8
10+
11+
exclude-rules:
12+
# Exclude some linters from running on tests files.
13+
- path: _test\.go
14+
linters:
15+
- errcheck

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@ GOCLEAN=$(GOCMD) clean
66
GOTEST=$(GOCMD) test
77
GOGET=$(GOCMD) get
88
GOMOD=$(GOCMD) mod
9+
GOFMT=$(GOCMD) fmt
910

1011
.PHONY: all test coverage
1112
all: test coverage
1213

14+
checkfmt:
15+
@echo 'Checking gofmt';\
16+
bash -c "diff -u <(echo -n) <(gofmt -d .)";\
17+
EXIT_CODE=$$?;\
18+
if [ "$$EXIT_CODE" -ne 0 ]; then \
19+
echo '$@: Go files must be formatted with gofmt'; \
20+
fi && \
21+
exit $$EXIT_CODE
22+
1323
get:
1424
$(GOGET) -t -v ./...
1525

1626
test: get
27+
$(GOFMT) ./...
1728
$(GOTEST) -race -covermode=atomic ./...
1829

1930
coverage: get test

client.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package redis_bloom_go
22

33
import (
44
"errors"
5-
"strings"
6-
"strconv"
75
"github.com/gomodule/redigo/redis"
6+
"strconv"
7+
"strings"
88
)
99

1010
// TODO: refactor this hard limit and revise client locking
@@ -35,7 +35,6 @@ func NewClient(addr, name string, authPass *string) *Client {
3535
return ret
3636
}
3737

38-
3938
// NewClientFromPool creates a new Client with the given pool and client name
4039
func NewClientFromPool(pool *redis.Pool, name string) *Client {
4140
ret := &Client{
@@ -45,50 +44,49 @@ func NewClientFromPool(pool *redis.Pool, name string) *Client {
4544
return ret
4645
}
4746

48-
// Reserve - Creates an empty Bloom Filter with a given desired error ratio and initial capacity.
47+
// Reserve - Creates an empty Bloom Filter with a given desired error ratio and initial capacity.
4948
// args:
5049
// key - the name of the filter
5150
// error_rate - the desired probability for false positives
52-
// capacity - the number of entries you intend to add to the filter
51+
// capacity - the number of entries you intend to add to the filter
5352
func (client *Client) Reserve(key string, error_rate float64, capacity uint64) (err error) {
5453
conn := client.Pool.Get()
5554
defer conn.Close()
56-
_, err = conn.Do("BF.RESERVE", key, strconv.FormatFloat(error_rate, 'g', 16, 64), capacity)
55+
_, err = conn.Do("BF.RESERVE", key, strconv.FormatFloat(error_rate, 'g', 16, 64), capacity)
5756
return err
5857
}
5958

60-
6159
// Add - Add (or create and add) a new value to the filter
6260
// args:
63-
// key - the name of the filter
64-
// item - the item to add
61+
// key - the name of the filter
62+
// item - the item to add
6563
func (client *Client) Add(key string, item string) (exists bool, err error) {
6664
conn := client.Pool.Get()
6765
defer conn.Close()
6866
return redis.Bool(conn.Do("BF.ADD", key, item))
6967
}
7068

71-
// Exists - Determines whether an item may exist in the Bloom Filter or not.
69+
// Exists - Determines whether an item may exist in the Bloom Filter or not.
7270
// args:
73-
// key - the name of the filter
74-
// item - the item to check for
71+
// key - the name of the filter
72+
// item - the item to check for
7573
func (client *Client) Exists(key string, item string) (exists bool, err error) {
7674
conn := client.Pool.Get()
7775
defer conn.Close()
7876
return redis.Bool(conn.Do("BF.EXISTS", key, item))
7977
}
8078

81-
// Info - Return information about key
79+
// Info - Return information about key
8280
// args:
83-
// key - the name of the filter
81+
// key - the name of the filter
8482
func (client *Client) Info(key string) (info map[string]int64, err error) {
8583
conn := client.Pool.Get()
8684
defer conn.Close()
8785
result, err := conn.Do("BF.INFO", key)
8886
if err != nil {
8987
return nil, err
9088
}
91-
89+
9290
values, err := redis.Values(result, nil)
9391
if err != nil {
9492
return nil, err
@@ -98,7 +96,7 @@ func (client *Client) Info(key string) (info map[string]int64, err error) {
9896
}
9997
info = map[string]int64{}
10098
for i := 0; i < len(values); i += 2 {
101-
key, err = redis.String(values[i], nil)
99+
key, err = redis.String(values[i], nil)
102100
if err != nil {
103101
return nil, err
104102
}
@@ -107,5 +105,5 @@ func (client *Client) Info(key string) (info map[string]int64, err error) {
107105
return nil, err
108106
}
109107
}
110-
return info, nil
108+
return info, nil
111109
}

client_test.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package redis_bloom_go
22

33
import (
4+
"github.com/gomodule/redigo/redis"
5+
"github.com/stretchr/testify/assert"
46
"os"
57
"testing"
68
"time"
7-
"github.com/gomodule/redigo/redis"
8-
"github.com/stretchr/testify/assert"
99
)
1010

11-
1211
func getTestConnectionDetails() (string, string) {
1312
value, exists := os.LookupEnv("REDISBLOOM_TEST_HOST")
1413
host := "localhost:6379"
@@ -32,7 +31,6 @@ func createClient() *Client {
3231
return NewClient(host, "test_client", ptr)
3332
}
3433

35-
3634
func TestNewClientFromPool(t *testing.T) {
3735
host, password := getTestConnectionDetails()
3836
pool := &redis.Pool{Dial: func() (redis.Conn, error) {
@@ -65,33 +63,33 @@ func TestReserve(t *testing.T) {
6563
key := "test_RESERVE"
6664
err := client.Reserve(key, 0.1, 1000)
6765
assert.Nil(t, err)
68-
66+
6967
info, err := client.Info(key)
7068
assert.Nil(t, err)
7169
assert.Equal(t, info, map[string]int64{
72-
"Capacity": 1000,
73-
"Expansion rate": 2,
74-
"Number of filters": 1,
75-
"Number of items inserted": 0,
76-
"Size": 932,
70+
"Capacity": 1000,
71+
"Expansion rate": 2,
72+
"Number of filters": 1,
73+
"Number of items inserted": 0,
74+
"Size": 932,
7775
})
78-
76+
7977
err = client.Reserve(key, 0.1, 1000)
8078
assert.NotNil(t, err)
8179
}
8280

8381
func TestAdd(t *testing.T) {
8482
client.FlushAll()
8583
key := "test_ADD"
86-
value := "test_ADD_value";
84+
value := "test_ADD_value"
8785
exists, err := client.Add(key, value)
8886
assert.Nil(t, err)
8987
assert.True(t, exists)
90-
88+
9189
info, err := client.Info(key)
9290
assert.Nil(t, err)
9391
assert.NotNil(t, info)
94-
92+
9593
exists, err = client.Add(key, value)
9694
assert.Nil(t, err)
9795
assert.False(t, exists)
@@ -100,11 +98,11 @@ func TestAdd(t *testing.T) {
10098
func TestExists(t *testing.T) {
10199
client.FlushAll()
102100
client.Add("test_ADD", "test_EXISTS")
103-
101+
104102
exists, err := client.Exists("test_ADD", "test_EXISTS")
105103
assert.Nil(t, err)
106104
assert.True(t, exists)
107-
105+
108106
exists, err = client.Exists("test_ADD", "test_EXISTS1")
109107
assert.Nil(t, err)
110108
assert.False(t, exists)

pool.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type ConnPool interface {
1717
type SingleHostPool struct {
1818
*redis.Pool
1919
}
20+
2021
//
2122
//func (s SingleHostPool) Close() {
2223
// s.Pool.Close()
@@ -39,7 +40,6 @@ type MultiHostPool struct {
3940
authPass *string
4041
}
4142

42-
4343
func (p *MultiHostPool) Close() (err error) {
4444
p.Lock()
4545
defer p.Unlock()
@@ -57,7 +57,6 @@ func (p *MultiHostPool) Close() (err error) {
5757
return
5858
}
5959

60-
6160
func NewMultiHostPool(hosts []string, authPass *string) *MultiHostPool {
6261
return &MultiHostPool{
6362
pools: make(map[string]*redis.Pool, len(hosts)),

0 commit comments

Comments
 (0)