Style: use gofumpt for fmt

This commit is contained in:
Dreamacro 2021-10-10 23:44:09 +08:00
parent 4ce35870fe
commit f1cf7e9269
34 changed files with 78 additions and 84 deletions

View file

@ -30,9 +30,8 @@ jobs:
- name: Get dependencies, run test and static check
run: |
go test ./...
go vet ./...
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck -- $(go list ./...)
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run --disable-all -E govet -E gofumpt -E megacheck ./...
- name: Build
if: startsWith(github.ref, 'refs/tags/')

View file

@ -112,5 +112,9 @@ $(zip_releases): %.zip : %
all-arch: $(PLATFORM_LIST) $(WINDOWS_ARCH_LIST)
releases: $(gz_releases) $(zip_releases)
lint:
golangci-lint run --disable-all -E govet -E gofumpt -E megacheck ./...
clean:
rm $(BINDIR)/*

View file

@ -12,8 +12,8 @@ import (
)
var (
fileMode os.FileMode = 0666
dirMode os.FileMode = 0755
fileMode os.FileMode = 0o666
dirMode os.FileMode = 0o755
)
type parser = func([]byte) (interface{}, error)

View file

@ -10,9 +10,7 @@ import (
types "github.com/Dreamacro/clash/constant/provider"
)
var (
errVehicleType = errors.New("unsupport vehicle type")
)
var errVehicleType = errors.New("unsupport vehicle type")
type healthCheckSchema struct {
Enable bool `provider:"enable"`

View file

@ -149,7 +149,6 @@ func TestSetWithExpire(t *testing.T) {
assert.Equal(t, nil, res)
assert.Equal(t, time.Time{}, expires)
assert.Equal(t, false, exist)
}
func TestStale(t *testing.T) {

View file

@ -67,7 +67,6 @@ func (d *digest32) bmix(p []byte) (tail []byte) {
}
func (d *digest32) Sum32() (h1 uint32) {
h1 = d.h1
var k1 uint32

View file

@ -38,7 +38,7 @@ func TestObservable_MultiSubscribe(t *testing.T) {
src := NewObservable(iter)
ch1, _ := src.Subscribe()
ch2, _ := src.Subscribe()
var count = atomic.NewInt32(0)
count := atomic.NewInt32(0)
var wg sync.WaitGroup
wg.Add(2)

View file

@ -53,6 +53,7 @@ func (alloc *Allocator) Put(buf []byte) error {
}
//lint:ignore SA6002 ignore temporarily
//nolint
alloc.buffers[bits].Put(buf)
return nil
}

View file

@ -12,7 +12,7 @@ import (
func TestBasic(t *testing.T) {
single := NewSingle(time.Millisecond * 30)
foo := 0
var shardCount = atomic.NewInt32(0)
shardCount := atomic.NewInt32(0)
call := func() (interface{}, error) {
foo++
time.Sleep(time.Millisecond * 5)

View file

@ -5,8 +5,10 @@ import (
"testing"
)
var decoder = NewDecoder(Option{TagName: "test"})
var weakTypeDecoder = NewDecoder(Option{TagName: "test", WeaklyTypedInput: true})
var (
decoder = NewDecoder(Option{TagName: "test"})
weakTypeDecoder = NewDecoder(Option{TagName: "test", WeaklyTypedInput: true})
)
type Baz struct {
Foo int `test:"foo"`

View file

@ -1,8 +1,6 @@
package dialer
var (
DefaultOptions []Option
)
var DefaultOptions []Option
type config struct {
skipDefault bool

View file

@ -15,8 +15,10 @@ type Interface struct {
HardwareAddr net.HardwareAddr
}
var ErrIfaceNotFound = errors.New("interface not found")
var ErrAddrNotFound = errors.New("addr not found")
var (
ErrIfaceNotFound = errors.New("interface not found")
ErrAddrNotFound = errors.New("addr not found")
)
var interfaces = singledo.NewSingle(time.Second * 20)

View file

@ -9,8 +9,10 @@ import (
"github.com/oschwald/geoip2-golang"
)
var mmdb *geoip2.Reader
var once sync.Once
var (
mmdb *geoip2.Reader
once sync.Once
)
func LoadFromBytes(buffer []byte) {
once.Do(func() {

View file

@ -25,8 +25,10 @@ var nativeEndian = func() binary.ByteOrder {
return binary.LittleEndian
}()
type SocketResolver func(network string, ip net.IP, srcPort int) (inode, uid int, err error)
type ProcessNameResolver func(inode, uid int) (name string, err error)
type (
SocketResolver func(network string, ip net.IP, srcPort int) (inode, uid int, err error)
ProcessNameResolver func(inode, uid int) (name string, err error)
)
// export for android
var (

View file

@ -16,7 +16,7 @@ import (
var (
initOnce sync.Once
fileMode os.FileMode = 0666
fileMode os.FileMode = 0o666
defaultCache *CacheFile
bucketSelected = []byte("selected")
@ -41,7 +41,6 @@ func (c *CacheFile) SetSelected(group, selected string) {
}
return bucket.Put([]byte(group), []byte(selected))
})
if err != nil {
log.Warnln("[CacheFile] write cache to %s failed: %s", c.db.Path(), err.Error())
return

View file

@ -4,7 +4,5 @@ import (
"go.uber.org/atomic"
)
var (
// StoreSelected is a global switch for storing selected proxy to cache
StoreSelected = atomic.NewBool(true)
)
// StoreSelected is a global switch for storing selected proxy to cache
var StoreSelected = atomic.NewBool(true)

View file

@ -12,10 +12,8 @@ const (
domainStep = "."
)
var (
// ErrInvalidDomain means insert domain is invalid
ErrInvalidDomain = errors.New("invalid domain")
)
// ErrInvalidDomain means insert domain is invalid
var ErrInvalidDomain = errors.New("invalid domain")
// DomainTrie contains the main logic for adding and searching nodes for domain segments.
// support wildcard domain (e.g *.google.com)

View file

@ -18,7 +18,7 @@ func downloadMMDB(path string) (err error) {
}
defer resp.Body.Close()
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644)
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
@ -54,7 +54,7 @@ func initMMDB() error {
func Init(dir string) error {
// initial homedir
if _, err := os.Stat(dir); os.IsNotExist(err) {
if err := os.MkdirAll(dir, 0777); err != nil {
if err := os.MkdirAll(dir, 0o777); err != nil {
return fmt.Errorf("can't create config directory %s: %s", dir, err.Error())
}
}
@ -62,7 +62,7 @@ func Init(dir string) error {
// initial config.yaml
if _, err := os.Stat(C.Path.Config()); os.IsNotExist(err) {
log.Infoln("Can't find config, create a initial config file")
f, err := os.OpenFile(C.Path.Config(), os.O_CREATE|os.O_WRONLY, 0644)
f, err := os.OpenFile(C.Path.Config(), os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return fmt.Errorf("can't create file %s: %s", C.Path.Config(), err.Error())
}

View file

@ -32,6 +32,7 @@ func (inf *ipnetFilter) Match(ip net.IP) bool {
type fallbackDomainFilter interface {
Match(domain string) bool
}
type domainFilter struct {
tree *trie.DomainTrie
}

View file

@ -14,8 +14,10 @@ import (
D "github.com/miekg/dns"
)
type handler func(ctx *context.DNSContext, r *D.Msg) (*D.Msg, error)
type middleware func(next handler) handler
type (
handler func(ctx *context.DNSContext, r *D.Msg) (*D.Msg, error)
middleware func(next handler) handler
)
func withHosts(hosts *trie.DomainTrie) middleware {
return func(next handler) handler {

View file

@ -215,7 +215,6 @@ func (r *Resolver) shouldOnlyQueryFallback(m *D.Msg) bool {
}
func (r *Resolver) ipExchange(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
if matched := r.matchPolicy(m); len(matched) != 0 {
res := <-r.asyncExchange(ctx, matched, m)
return res.Msg, res.Error

View file

@ -13,14 +13,12 @@ import (
D "github.com/miekg/dns"
)
var (
// EnhancedModeMapping is a mapping for EnhancedMode enum
EnhancedModeMapping = map[string]EnhancedMode{
NORMAL.String(): NORMAL,
FAKEIP.String(): FAKEIP,
MAPPING.String(): MAPPING,
}
)
// EnhancedModeMapping is a mapping for EnhancedMode enum
var EnhancedModeMapping = map[string]EnhancedMode{
NORMAL.String(): NORMAL,
FAKEIP.String(): FAKEIP,
MAPPING.String(): MAPPING,
}
const (
NORMAL EnhancedMode = iota

View file

@ -24,9 +24,7 @@ import (
"github.com/Dreamacro/clash/tunnel"
)
var (
mux sync.Mutex
)
var mux sync.Mutex
func readConfig(path string) ([]byte, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {

View file

@ -4,9 +4,7 @@ import (
"github.com/Dreamacro/clash/component/auth"
)
var (
authenticator auth.Authenticator
)
var authenticator auth.Authenticator
func Authenticator() auth.Authenticator {
return authenticator

View file

@ -5,16 +5,14 @@ import (
"errors"
)
var (
// LogLevelMapping is a mapping for LogLevel enum
LogLevelMapping = map[string]LogLevel{
ERROR.String(): ERROR,
WARNING.String(): WARNING,
INFO.String(): INFO,
DEBUG.String(): DEBUG,
SILENT.String(): SILENT,
}
)
// LogLevelMapping is a mapping for LogLevel enum
var LogLevelMapping = map[string]LogLevel{
ERROR.String(): ERROR,
WARNING.String(): WARNING,
INFO.String(): INFO,
DEBUG.String(): DEBUG,
SILENT.String(): SILENT,
}
const (
DEBUG LogLevel = iota

View file

@ -27,12 +27,10 @@ var (
ErrSmallBuffer = errors.New("buffer too small")
)
var (
defaultHeader = http.Header{
"content-type": []string{"application/grpc"},
"user-agent": []string{"grpc-go/1.36.0"},
}
)
var defaultHeader = http.Header{
"content-type": []string{"application/grpc"},
"user-agent": []string{"grpc-go/1.36.0"},
}
type DialFn = func(network, addr string) (net.Conn, error)

View file

@ -78,6 +78,7 @@ func (to *TLSObfs) Read(b []byte) (int, error) {
// type + ver = 3
return to.read(b, 3)
}
func (to *TLSObfs) Write(b []byte) (int, error) {
length := len(b)
for i := 0; i < length; i += chunkSize {

View file

@ -20,6 +20,7 @@ func (sc *snellCipher) SaltSize() int { return 16 }
func (sc *snellCipher) Encrypter(salt []byte) (cipher.AEAD, error) {
return sc.makeAEAD(snellKDF(sc.psk, salt, sc.KeySize()))
}
func (sc *snellCipher) Decrypter(salt []byte) (cipher.AEAD, error) {
return sc.makeAEAD(snellKDF(sc.psk, salt, sc.KeySize()))
}

View file

@ -30,9 +30,7 @@ const (
Version byte = 1
)
var (
endSignal = []byte{}
)
var endSignal = []byte{}
type Snell struct {
net.Conn

View file

@ -184,7 +184,7 @@ func isReservedIP(ip net.IP) bool {
}
func readUntilNull(r io.Reader) ([]byte, error) {
var buf = &bytes.Buffer{}
buf := &bytes.Buffer{}
var data [1]byte
for {

View file

@ -14,8 +14,10 @@ import (
"github.com/Dreamacro/clash/transport/ssr/tools"
)
type hmacMethod func(key, data []byte) []byte
type hashDigestMethod func([]byte) []byte
type (
hmacMethod func(key, data []byte) []byte
hashDigestMethod func([]byte) []byte
)
func init() {
register("auth_aes128_sha1", newAuthAES128SHA1, 9)

View file

@ -92,7 +92,7 @@ func sealVMessAEADHeader(key [16]byte, data []byte, t time.Time) []byte {
payloadHeaderAEADEncrypted = payloadHeaderAEAD.Seal(nil, payloadHeaderAEADNonce, data, generatedAuthID[:])
}
var outputBuffer = &bytes.Buffer{}
outputBuffer := &bytes.Buffer{}
outputBuffer.Write(generatedAuthID[:])
outputBuffer.Write(payloadHeaderLengthAEADEncrypted)

View file

@ -28,6 +28,7 @@ type websocketConn struct {
rMux sync.Mutex
wMux sync.Mutex
}
type websocketWithEarlyDataConn struct {
net.Conn
underlay net.Conn

View file

@ -8,14 +8,12 @@ import (
type TunnelMode int
var (
// ModeMapping is a mapping for Mode enum
ModeMapping = map[string]TunnelMode{
Global.String(): Global,
Rule.String(): Rule,
Direct.String(): Direct,
}
)
// ModeMapping is a mapping for Mode enum
var ModeMapping = map[string]TunnelMode{
Global.String(): Global,
Rule.String(): Rule,
Direct.String(): Direct,
}
const (
Global TunnelMode = iota