Skip to content

Commit 6a653f8

Browse files
committed
chore: golangci
1 parent 87ef084 commit 6a653f8

File tree

6 files changed

+84
-17
lines changed

6 files changed

+84
-17
lines changed

.golangci.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
linters-settings:
2+
govet:
3+
check-shadowing: true
4+
settings:
5+
printf:
6+
funcs:
7+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
8+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
9+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
10+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
11+
golint:
12+
min-confidence: 0
13+
gocyclo:
14+
min-complexity: 10
15+
maligned:
16+
suggest-new: true
17+
dupl:
18+
threshold: 100
19+
goconst:
20+
min-len: 2
21+
min-occurrences: 2
22+
depguard:
23+
list-type: blacklist
24+
packages:
25+
# logging is allowed only by logutils.Log, logrus
26+
# is allowed to use only in logutils package
27+
- github.com/sirupsen/logrus
28+
misspell:
29+
locale: US
30+
lll:
31+
line-length: 140
32+
goimports:
33+
local-prefixes: github.com/golangci/golangci-lint
34+
gocritic:
35+
enabled-tags:
36+
- performance
37+
- style
38+
- experimental
39+
disabled-checks:
40+
- wrapperFunc
41+
- dupImport # https://github.com/go-critic/go-critic/issues/845
42+
43+
linters:
44+
enable-all: true
45+
disable:
46+
- maligned
47+
- prealloc
48+
- gochecknoglobals
49+
50+
run:
51+
skip-dirs:
52+
- test/testdata_etc
53+
- pkg/golinters/goanalysis/(checker|passes)
54+
55+
issues:
56+
exclude-rules:
57+
- text: "weak cryptographic primitive"
58+
linters:
59+
- gosec
60+
61+
62+

Gopkg.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
[[constraint]]
2929
name = "github.com/xiaojiaoyu100/curlew"
30-
version = "0.0.1"
30+
version = "0.1.0"
3131

3232
[prune]
3333
unused-packages = true

cache.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package roc
33
import (
44
"container/list"
55
"context"
6-
"github.com/xiaojiaoyu100/curlew"
76
"time"
7+
8+
"github.com/xiaojiaoyu100/curlew"
89
)
910

1011
type Cache struct {
@@ -16,7 +17,6 @@ type Cache struct {
1617
}
1718

1819
func New(setters ...Setter) (*Cache, error) {
19-
var err error
2020
c := new(Cache)
2121
c.GCInterval = 60 * time.Second
2222
c.BucketNum = 16
@@ -41,7 +41,10 @@ func New(setters ...Setter) (*Cache, error) {
4141
c.buckets = append(c.buckets, bucket)
4242
}
4343

44-
c.dispatcher, err = curlew.New()
44+
monitor := func(err error) {}
45+
46+
var err error
47+
c.dispatcher, err = curlew.New(curlew.WithMonitor(monitor))
4548
if err != nil {
4649
return nil, err
4750
}
@@ -58,17 +61,15 @@ func (c *Cache) gc() {
5861
for {
5962
select {
6063
case <-ticker.C:
61-
{
62-
for _, bucket := range c.buckets {
63-
j := curlew.NewJob()
64-
j.Fn = func(_ context.Context, arg interface{}) error {
65-
b := arg.(*Bucket)
66-
b.gc()
67-
return nil
68-
}
69-
j.Arg = bucket
70-
c.dispatcher.SubmitAsync(j)
64+
for _, bucket := range c.buckets {
65+
j := curlew.NewJob()
66+
j.Fn = func(_ context.Context, arg interface{}) error {
67+
b := arg.(*Bucket)
68+
b.gc()
69+
return nil
7170
}
71+
j.Arg = bucket
72+
c.dispatcher.SubmitAsync(j)
7273
}
7374
case <-c.close:
7475
return

setter.go

+2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ func isPowerOfTwo(num int) bool {
1010
return (num != 0) && ((num & (num - 1)) == 0)
1111
}
1212

13+
// WithBucketNum set the number of buckets
1314
func WithBucketNum(num int) Setter {
1415
return func(c *Cache) error {
1516
c.BucketNum = num
1617
return nil
1718
}
1819
}
1920

21+
// WithGCInterval sets the gc cycle.
2022
func WithGCInterval(interval time.Duration) Setter {
2123
return func(c *Cache) error {
2224
c.GCInterval = interval

unit.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package roc
22

33
import "time"
44

5+
// Unit represents a store unit
56
type Unit struct {
67
Key string
78
Data interface{}
89
ExpirationTime time.Time
910
}
1011

12+
// Expire returns true when unit has expired.
1113
func (u *Unit) Expire() bool {
1214
return u.ExpirationTime.Before(time.Now().UTC())
1315
}

0 commit comments

Comments
 (0)