From b66137f9eca1c7c70b04750efcd15c8f26e24655 Mon Sep 17 00:00:00 2001 From: solo-bot Date: Sun, 7 Jun 2026 21:57:17 +0800 Subject: [PATCH] ci: add GitHub Actions checks (#25) --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++++ .travis.yml | 25 ------------------------- client.go | 7 +------ socks5.go | 4 ++-- 4 files changed, 42 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9be7ce3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +on: + pull_request: + branches: + - master + push: + branches: + - master + +jobs: + checks: + runs-on: ubuntu-latest + env: + CGO_ENABLED: "0" + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Check formatting + run: | + test -z "$(gofmt -l .)" + + - name: Run go vet + run: go vet ./... + + - name: Run tests + run: go test ./... + + - name: Run staticcheck + run: | + go install honnef.co/go/tools/cmd/staticcheck@latest + staticcheck ./... diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index da8ca08..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: go -sudo: false -go: - - 1.10.x - - 1.11.x - - master - -matrix: - fast_finish: true - include: - - go: 1.11.x - env: GO111MODULE=on - - -before_install: - - if [[ "${GO111MODULE}" = "on" ]]; then mkdir "${HOME}/go"; export GOPATH="${HOME}/go"; fi - - if [[ "${GO111MODULE}" = "on" ]]; then export PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"; fi - -install: - - go get github.com/stretchr/testify - -go_import_path: github.com/shikanon/socks5proxy - -script: - - go test -cover \ No newline at end of file diff --git a/client.go b/client.go index c7bf1cd..1996ba8 100644 --- a/client.go +++ b/client.go @@ -12,11 +12,6 @@ import ( "sync" ) -type TcpClient struct { - conn *net.TCPConn - server *net.TCPAddr -} - func handleProxyRequest(localClient *net.TCPConn, serverAddr *net.TCPAddr, auth socks5Auth, recvHTTPProto string) error { // 远程连接IO @@ -105,7 +100,7 @@ func handleProxyRequest(localClient *net.TCPConn, serverAddr *net.TCPAddr, auth binary.Write(dstPortBuff, binary.BigEndian, dstPortInt) dstPortBytes := dstPortBuff.Bytes() // int为8字节 resp = append(resp, dstPortBytes[len(dstPortBytes)-2:]...) - n, err = auth.EncodeWrite(dstServer, resp) + _, err = auth.EncodeWrite(dstServer, resp) if err != nil { return err } diff --git a/socks5.go b/socks5.go index 4450f3e..7b12ff7 100644 --- a/socks5.go +++ b/socks5.go @@ -53,7 +53,7 @@ func (s *ProtocolVersion) HandleHandshake(b []byte) ([]byte, error) { } s.VER = b[0] //ReadByte reads and returns a single byte,第一个参数为socks的版本号 if s.VER != 0x05 { - return nil, errors.New("协议错误, version版本不为5!") + return nil, errors.New("协议错误, version版本不为5") } s.NMETHODS = b[1] //nmethods是记录methods的长度的。nmethods的长度是1个字节 if n != int(2+s.NMETHODS) { @@ -196,7 +196,7 @@ func (s *Socks5Resolution) LSTRequest(b []byte) ([]byte, error) { s.CMD = b[1] if s.CMD != 1 { - return nil, errors.New("客户端请求类型不为代理连接, 其他功能暂时不支持.") + return nil, errors.New("客户端请求类型不为代理连接, 其他功能暂时不支持") } s.RSV = b[2] //RSV保留字端,值长度为1个字节