From 5045ca457482e1743989214985754054240440b7 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Tue, 4 Apr 2023 14:53:59 +0800 Subject: [PATCH] Chore: add some linters and clean up the code --- .golangci.yaml | 12 +++++++++--- adapter/outbound/vmess.go | 6 +++--- component/process/process_windows.go | 2 +- transport/simple-obfs/http.go | 2 +- transport/socks5/socks5.go | 2 +- transport/vmess/conn.go | 2 +- transport/vmess/h2.go | 2 +- transport/vmess/http.go | 2 +- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 6c99152..2650fef 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,10 +1,16 @@ linters: disable-all: true enable: - - gofumpt - - staticcheck - - govet - gci + - gofumpt + - gosimple + - govet + - ineffassign + - misspell + - staticcheck + - unconvert + - unused + - usestdlibvars linters-settings: gci: diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index 8fa74fb..d5d74f4 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -340,15 +340,15 @@ func parseVmessAddr(metadata *C.Metadata) *vmess.DstAddr { var addr []byte switch metadata.AddrType() { case socks5.AtypIPv4: - addrType = byte(vmess.AtypIPv4) + addrType = vmess.AtypIPv4 addr = make([]byte, net.IPv4len) copy(addr[:], metadata.DstIP.To4()) case socks5.AtypIPv6: - addrType = byte(vmess.AtypIPv6) + addrType = vmess.AtypIPv6 addr = make([]byte, net.IPv6len) copy(addr[:], metadata.DstIP.To16()) case socks5.AtypDomainName: - addrType = byte(vmess.AtypDomainName) + addrType = vmess.AtypDomainName addr = make([]byte, len(metadata.Host)+1) addr[0] = byte(len(metadata.Host)) copy(addr[1:], []byte(metadata.Host)) diff --git a/component/process/process_windows.go b/component/process/process_windows.go index 26a389a..5cbcdf7 100644 --- a/component/process/process_windows.go +++ b/component/process/process_windows.go @@ -62,7 +62,7 @@ func findProcessName(network string, ip net.IP, srcPort int) (string, error) { err := initWin32API() if err != nil { log.Errorln("Initialize PROCESS-NAME failed: %s", err.Error()) - log.Warnln("All PROCESS-NAMES rules will be skiped") + log.Warnln("All PROCESS-NAMES rules will be skipped") return } }) diff --git a/transport/simple-obfs/http.go b/transport/simple-obfs/http.go index 5850b29..97e7159 100644 --- a/transport/simple-obfs/http.go +++ b/transport/simple-obfs/http.go @@ -65,7 +65,7 @@ func (ho *HTTPObfs) Write(b []byte) (int, error) { if ho.firstRequest { randBytes := make([]byte, 16) rand.Read(randBytes) - req, _ := http.NewRequest("GET", fmt.Sprintf("http://%s/", ho.host), bytes.NewBuffer(b[:])) + req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s/", ho.host), bytes.NewBuffer(b[:])) req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", mathRand.Int()%54, mathRand.Int()%2)) req.Header.Set("Upgrade", "websocket") req.Header.Set("Connection", "Upgrade") diff --git a/transport/socks5/socks5.go b/transport/socks5/socks5.go index 7d4f11a..26ce379 100644 --- a/transport/socks5/socks5.go +++ b/transport/socks5/socks5.go @@ -159,7 +159,7 @@ func ServerHandshake(rw net.Conn, authenticator auth.Authenticator) (addr Addr, pass := string(authBuf[:passLen]) // Verify - if ok := authenticator.Verify(string(user), string(pass)); !ok { + if ok := authenticator.Verify(user, pass); !ok { rw.Write([]byte{1, 1}) err = ErrAuth return diff --git a/transport/vmess/conn.go b/transport/vmess/conn.go index 9789a2f..5d4bbde 100644 --- a/transport/vmess/conn.go +++ b/transport/vmess/conn.go @@ -76,7 +76,7 @@ func (vc *Conn) sendRequest() error { p := mathRand.Intn(16) // P Sec Reserve Cmd - buf.WriteByte(byte(p<<4) | byte(vc.security)) + buf.WriteByte(byte(p<<4) | vc.security) buf.WriteByte(0) if vc.dst.UDP { buf.WriteByte(CommandUDP) diff --git a/transport/vmess/h2.go b/transport/vmess/h2.go index d4e8160..330c8b6 100644 --- a/transport/vmess/h2.go +++ b/transport/vmess/h2.go @@ -30,7 +30,7 @@ func (hc *h2Conn) establishConn() error { path := hc.cfg.Path // TODO: connect use VMess Host instead of H2 Host req := http.Request{ - Method: "PUT", + Method: http.MethodPut, Host: host, URL: &url.URL{ Scheme: "https", diff --git a/transport/vmess/http.go b/transport/vmess/http.go index 1c09e21..3c15765 100644 --- a/transport/vmess/http.go +++ b/transport/vmess/http.go @@ -58,7 +58,7 @@ func (hc *httpConn) Write(b []byte) (int, error) { } u := fmt.Sprintf("http://%s%s", host, path) - req, _ := http.NewRequest("GET", u, bytes.NewBuffer(b)) + req, _ := http.NewRequest(http.MethodGet, u, bytes.NewBuffer(b)) for key, list := range hc.cfg.Headers { req.Header.Set(key, list[rand.Intn(len(list))]) }