Skip to content

Commit f1cf7e9

Browse files
committed
Style: use gofumpt for fmt
1 parent 4ce3587 commit f1cf7e9

File tree

34 files changed

+78
-84
lines changed

34 files changed

+78
-84
lines changed

.github/workflows/go.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ jobs:
3030
- name: Get dependencies, run test and static check
3131
run: |
3232
go test ./...
33-
go vet ./...
34-
go install honnef.co/go/tools/cmd/staticcheck@latest
35-
staticcheck -- $(go list ./...)
33+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
34+
golangci-lint run --disable-all -E govet -E gofumpt -E megacheck ./...
3635
3736
- name: Build
3837
if: startsWith(github.ref, 'refs/tags/')

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,9 @@ $(zip_releases): %.zip : %
112112
all-arch: $(PLATFORM_LIST) $(WINDOWS_ARCH_LIST)
113113

114114
releases: $(gz_releases) $(zip_releases)
115+
116+
lint:
117+
golangci-lint run --disable-all -E govet -E gofumpt -E megacheck ./...
118+
115119
clean:
116120
rm $(BINDIR)/*

adapter/provider/fetcher.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
)
1313

1414
var (
15-
fileMode os.FileMode = 0666
16-
dirMode os.FileMode = 0755
15+
fileMode os.FileMode = 0o666
16+
dirMode os.FileMode = 0o755
1717
)
1818

1919
type parser = func([]byte) (interface{}, error)

adapter/provider/parser.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import (
1010
types "github.com/Dreamacro/clash/constant/provider"
1111
)
1212

13-
var (
14-
errVehicleType = errors.New("unsupport vehicle type")
15-
)
13+
var errVehicleType = errors.New("unsupport vehicle type")
1614

1715
type healthCheckSchema struct {
1816
Enable bool `provider:"enable"`

common/cache/lrucache_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ func TestSetWithExpire(t *testing.T) {
149149
assert.Equal(t, nil, res)
150150
assert.Equal(t, time.Time{}, expires)
151151
assert.Equal(t, false, exist)
152-
153152
}
154153

155154
func TestStale(t *testing.T) {

common/murmur3/murmur32.go

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func (d *digest32) bmix(p []byte) (tail []byte) {
6767
}
6868

6969
func (d *digest32) Sum32() (h1 uint32) {
70-
7170
h1 = d.h1
7271

7372
var k1 uint32

common/observable/observable_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestObservable_MultiSubscribe(t *testing.T) {
3838
src := NewObservable(iter)
3939
ch1, _ := src.Subscribe()
4040
ch2, _ := src.Subscribe()
41-
var count = atomic.NewInt32(0)
41+
count := atomic.NewInt32(0)
4242

4343
var wg sync.WaitGroup
4444
wg.Add(2)

common/pool/alloc.go

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (alloc *Allocator) Put(buf []byte) error {
5353
}
5454

5555
//lint:ignore SA6002 ignore temporarily
56+
//nolint
5657
alloc.buffers[bits].Put(buf)
5758
return nil
5859
}

common/singledo/singledo_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestBasic(t *testing.T) {
1313
single := NewSingle(time.Millisecond * 30)
1414
foo := 0
15-
var shardCount = atomic.NewInt32(0)
15+
shardCount := atomic.NewInt32(0)
1616
call := func() (interface{}, error) {
1717
foo++
1818
time.Sleep(time.Millisecond * 5)

common/structure/structure_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"testing"
66
)
77

8-
var decoder = NewDecoder(Option{TagName: "test"})
9-
var weakTypeDecoder = NewDecoder(Option{TagName: "test", WeaklyTypedInput: true})
8+
var (
9+
decoder = NewDecoder(Option{TagName: "test"})
10+
weakTypeDecoder = NewDecoder(Option{TagName: "test", WeaklyTypedInput: true})
11+
)
1012

1113
type Baz struct {
1214
Foo int `test:"foo"`

component/dialer/options.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package dialer
22

3-
var (
4-
DefaultOptions []Option
5-
)
3+
var DefaultOptions []Option
64

75
type config struct {
86
skipDefault bool

component/iface/iface.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ type Interface struct {
1515
HardwareAddr net.HardwareAddr
1616
}
1717

18-
var ErrIfaceNotFound = errors.New("interface not found")
19-
var ErrAddrNotFound = errors.New("addr not found")
18+
var (
19+
ErrIfaceNotFound = errors.New("interface not found")
20+
ErrAddrNotFound = errors.New("addr not found")
21+
)
2022

2123
var interfaces = singledo.NewSingle(time.Second * 20)
2224

component/mmdb/mmdb.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
"github.com/oschwald/geoip2-golang"
1010
)
1111

12-
var mmdb *geoip2.Reader
13-
var once sync.Once
12+
var (
13+
mmdb *geoip2.Reader
14+
once sync.Once
15+
)
1416

1517
func LoadFromBytes(buffer []byte) {
1618
once.Do(func() {

component/process/process_linux.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ var nativeEndian = func() binary.ByteOrder {
2525
return binary.LittleEndian
2626
}()
2727

28-
type SocketResolver func(network string, ip net.IP, srcPort int) (inode, uid int, err error)
29-
type ProcessNameResolver func(inode, uid int) (name string, err error)
28+
type (
29+
SocketResolver func(network string, ip net.IP, srcPort int) (inode, uid int, err error)
30+
ProcessNameResolver func(inode, uid int) (name string, err error)
31+
)
3032

3133
// export for android
3234
var (

component/profile/cachefile/cache.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
var (
1818
initOnce sync.Once
19-
fileMode os.FileMode = 0666
19+
fileMode os.FileMode = 0o666
2020
defaultCache *CacheFile
2121

2222
bucketSelected = []byte("selected")
@@ -41,7 +41,6 @@ func (c *CacheFile) SetSelected(group, selected string) {
4141
}
4242
return bucket.Put([]byte(group), []byte(selected))
4343
})
44-
4544
if err != nil {
4645
log.Warnln("[CacheFile] write cache to %s failed: %s", c.db.Path(), err.Error())
4746
return

component/profile/profile.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ import (
44
"go.uber.org/atomic"
55
)
66

7-
var (
8-
// StoreSelected is a global switch for storing selected proxy to cache
9-
StoreSelected = atomic.NewBool(true)
10-
)
7+
// StoreSelected is a global switch for storing selected proxy to cache
8+
var StoreSelected = atomic.NewBool(true)

component/trie/domain.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ const (
1212
domainStep = "."
1313
)
1414

15-
var (
16-
// ErrInvalidDomain means insert domain is invalid
17-
ErrInvalidDomain = errors.New("invalid domain")
18-
)
15+
// ErrInvalidDomain means insert domain is invalid
16+
var ErrInvalidDomain = errors.New("invalid domain")
1917

2018
// DomainTrie contains the main logic for adding and searching nodes for domain segments.
2119
// support wildcard domain (e.g *.google.com)

config/initial.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func downloadMMDB(path string) (err error) {
1818
}
1919
defer resp.Body.Close()
2020

21-
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644)
21+
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0o644)
2222
if err != nil {
2323
return err
2424
}
@@ -54,15 +54,15 @@ func initMMDB() error {
5454
func Init(dir string) error {
5555
// initial homedir
5656
if _, err := os.Stat(dir); os.IsNotExist(err) {
57-
if err := os.MkdirAll(dir, 0777); err != nil {
57+
if err := os.MkdirAll(dir, 0o777); err != nil {
5858
return fmt.Errorf("can't create config directory %s: %s", dir, err.Error())
5959
}
6060
}
6161

6262
// initial config.yaml
6363
if _, err := os.Stat(C.Path.Config()); os.IsNotExist(err) {
6464
log.Infoln("Can't find config, create a initial config file")
65-
f, err := os.OpenFile(C.Path.Config(), os.O_CREATE|os.O_WRONLY, 0644)
65+
f, err := os.OpenFile(C.Path.Config(), os.O_CREATE|os.O_WRONLY, 0o644)
6666
if err != nil {
6767
return fmt.Errorf("can't create file %s: %s", C.Path.Config(), err.Error())
6868
}

dns/filters.go

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (inf *ipnetFilter) Match(ip net.IP) bool {
3232
type fallbackDomainFilter interface {
3333
Match(domain string) bool
3434
}
35+
3536
type domainFilter struct {
3637
tree *trie.DomainTrie
3738
}

dns/middleware.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
D "github.com/miekg/dns"
1515
)
1616

17-
type handler func(ctx *context.DNSContext, r *D.Msg) (*D.Msg, error)
18-
type middleware func(next handler) handler
17+
type (
18+
handler func(ctx *context.DNSContext, r *D.Msg) (*D.Msg, error)
19+
middleware func(next handler) handler
20+
)
1921

2022
func withHosts(hosts *trie.DomainTrie) middleware {
2123
return func(next handler) handler {

dns/resolver.go

-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ func (r *Resolver) shouldOnlyQueryFallback(m *D.Msg) bool {
215215
}
216216

217217
func (r *Resolver) ipExchange(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
218-
219218
if matched := r.matchPolicy(m); len(matched) != 0 {
220219
res := <-r.asyncExchange(ctx, matched, m)
221220
return res.Msg, res.Error

dns/util.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ import (
1313
D "github.com/miekg/dns"
1414
)
1515

16-
var (
17-
// EnhancedModeMapping is a mapping for EnhancedMode enum
18-
EnhancedModeMapping = map[string]EnhancedMode{
19-
NORMAL.String(): NORMAL,
20-
FAKEIP.String(): FAKEIP,
21-
MAPPING.String(): MAPPING,
22-
}
23-
)
16+
// EnhancedModeMapping is a mapping for EnhancedMode enum
17+
var EnhancedModeMapping = map[string]EnhancedMode{
18+
NORMAL.String(): NORMAL,
19+
FAKEIP.String(): FAKEIP,
20+
MAPPING.String(): MAPPING,
21+
}
2422

2523
const (
2624
NORMAL EnhancedMode = iota

hub/executor/executor.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ import (
2424
"github.com/Dreamacro/clash/tunnel"
2525
)
2626

27-
var (
28-
mux sync.Mutex
29-
)
27+
var mux sync.Mutex
3028

3129
func readConfig(path string) ([]byte, error) {
3230
if _, err := os.Stat(path); os.IsNotExist(err) {

listener/auth/auth.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"github.com/Dreamacro/clash/component/auth"
55
)
66

7-
var (
8-
authenticator auth.Authenticator
9-
)
7+
var authenticator auth.Authenticator
108

119
func Authenticator() auth.Authenticator {
1210
return authenticator

log/level.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ import (
55
"errors"
66
)
77

8-
var (
9-
// LogLevelMapping is a mapping for LogLevel enum
10-
LogLevelMapping = map[string]LogLevel{
11-
ERROR.String(): ERROR,
12-
WARNING.String(): WARNING,
13-
INFO.String(): INFO,
14-
DEBUG.String(): DEBUG,
15-
SILENT.String(): SILENT,
16-
}
17-
)
8+
// LogLevelMapping is a mapping for LogLevel enum
9+
var LogLevelMapping = map[string]LogLevel{
10+
ERROR.String(): ERROR,
11+
WARNING.String(): WARNING,
12+
INFO.String(): INFO,
13+
DEBUG.String(): DEBUG,
14+
SILENT.String(): SILENT,
15+
}
1816

1917
const (
2018
DEBUG LogLevel = iota

transport/gun/gun.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ var (
2727
ErrSmallBuffer = errors.New("buffer too small")
2828
)
2929

30-
var (
31-
defaultHeader = http.Header{
32-
"content-type": []string{"application/grpc"},
33-
"user-agent": []string{"grpc-go/1.36.0"},
34-
}
35-
)
30+
var defaultHeader = http.Header{
31+
"content-type": []string{"application/grpc"},
32+
"user-agent": []string{"grpc-go/1.36.0"},
33+
}
3634

3735
type DialFn = func(network, addr string) (net.Conn, error)
3836

transport/simple-obfs/tls.go

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (to *TLSObfs) Read(b []byte) (int, error) {
7878
// type + ver = 3
7979
return to.read(b, 3)
8080
}
81+
8182
func (to *TLSObfs) Write(b []byte) (int, error) {
8283
length := len(b)
8384
for i := 0; i < length; i += chunkSize {

transport/snell/cipher.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func (sc *snellCipher) SaltSize() int { return 16 }
2020
func (sc *snellCipher) Encrypter(salt []byte) (cipher.AEAD, error) {
2121
return sc.makeAEAD(snellKDF(sc.psk, salt, sc.KeySize()))
2222
}
23+
2324
func (sc *snellCipher) Decrypter(salt []byte) (cipher.AEAD, error) {
2425
return sc.makeAEAD(snellKDF(sc.psk, salt, sc.KeySize()))
2526
}

transport/snell/snell.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ const (
3030
Version byte = 1
3131
)
3232

33-
var (
34-
endSignal = []byte{}
35-
)
33+
var endSignal = []byte{}
3634

3735
type Snell struct {
3836
net.Conn

transport/socks4/socks4.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func isReservedIP(ip net.IP) bool {
184184
}
185185

186186
func readUntilNull(r io.Reader) ([]byte, error) {
187-
var buf = &bytes.Buffer{}
187+
buf := &bytes.Buffer{}
188188
var data [1]byte
189189

190190
for {

transport/ssr/protocol/auth_aes128_sha1.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
"github.com/Dreamacro/clash/transport/ssr/tools"
1515
)
1616

17-
type hmacMethod func(key, data []byte) []byte
18-
type hashDigestMethod func([]byte) []byte
17+
type (
18+
hmacMethod func(key, data []byte) []byte
19+
hashDigestMethod func([]byte) []byte
20+
)
1921

2022
func init() {
2123
register("auth_aes128_sha1", newAuthAES128SHA1, 9)

transport/vmess/header.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func sealVMessAEADHeader(key [16]byte, data []byte, t time.Time) []byte {
9292
payloadHeaderAEADEncrypted = payloadHeaderAEAD.Seal(nil, payloadHeaderAEADNonce, data, generatedAuthID[:])
9393
}
9494

95-
var outputBuffer = &bytes.Buffer{}
95+
outputBuffer := &bytes.Buffer{}
9696

9797
outputBuffer.Write(generatedAuthID[:])
9898
outputBuffer.Write(payloadHeaderLengthAEADEncrypted)

transport/vmess/websocket.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type websocketConn struct {
2828
rMux sync.Mutex
2929
wMux sync.Mutex
3030
}
31+
3132
type websocketWithEarlyDataConn struct {
3233
net.Conn
3334
underlay net.Conn

0 commit comments

Comments
 (0)