diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index f114c7bc..031660d0 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -15,7 +15,7 @@ jobs: # If you want to matrix build , you can append the following list. matrix: go_version: - - 1.13 + - 1.20 os: - ubuntu-latest @@ -54,7 +54,7 @@ jobs: /tmp/tools/license/license-header-checker -v -a -r -i vendor /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]] - name: Install go ci lint - run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0 + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.56.0 - name: Run Linter run: golangci-lint run --timeout=10m -v --disable-all --enable=govet --enable=staticcheck --enable=ineffassign --enable=misspell diff --git a/examples/echo/tcp-echo/client/assembly/common/build.sh b/examples/echo/tcp-echo/client/assembly/common/build.sh index 00763725..2652bafb 100644 --- a/examples/echo/tcp-echo/client/assembly/common/build.sh +++ b/examples/echo/tcp-echo/client/assembly/common/build.sh @@ -15,7 +15,8 @@ PROJECT_HOME=`pwd` TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +#version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +version="1.0" if [[ ${GOOS} == "windows" ]]; then TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe fi @@ -24,12 +25,12 @@ if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 # GFLAGS=-gcflags "-N -l" -race -v # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - else # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - fi TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} diff --git a/examples/echo/tcp-echo/server/assembly/common/build.sh b/examples/echo/tcp-echo/server/assembly/common/build.sh index 00763725..2652bafb 100644 --- a/examples/echo/tcp-echo/server/assembly/common/build.sh +++ b/examples/echo/tcp-echo/server/assembly/common/build.sh @@ -15,7 +15,8 @@ PROJECT_HOME=`pwd` TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +#version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +version="1.0" if [[ ${GOOS} == "windows" ]]; then TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe fi @@ -24,12 +25,12 @@ if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 # GFLAGS=-gcflags "-N -l" -race -v # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - else # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - fi TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} diff --git a/examples/echo/udp-echo/client/assembly/common/build.sh b/examples/echo/udp-echo/client/assembly/common/build.sh index 00763725..2652bafb 100644 --- a/examples/echo/udp-echo/client/assembly/common/build.sh +++ b/examples/echo/udp-echo/client/assembly/common/build.sh @@ -15,7 +15,8 @@ PROJECT_HOME=`pwd` TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +#version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +version="1.0" if [[ ${GOOS} == "windows" ]]; then TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe fi @@ -24,12 +25,12 @@ if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 # GFLAGS=-gcflags "-N -l" -race -v # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - else # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - fi TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} diff --git a/examples/echo/udp-echo/server/assembly/common/build.sh b/examples/echo/udp-echo/server/assembly/common/build.sh index 00763725..2652bafb 100644 --- a/examples/echo/udp-echo/server/assembly/common/build.sh +++ b/examples/echo/udp-echo/server/assembly/common/build.sh @@ -15,7 +15,8 @@ PROJECT_HOME=`pwd` TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +#version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +version="1.0" if [[ ${GOOS} == "windows" ]]; then TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe fi @@ -24,12 +25,12 @@ if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 # GFLAGS=-gcflags "-N -l" -race -v # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - else # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - fi TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} diff --git a/examples/echo/ws-echo/client/assembly/common/build.sh b/examples/echo/ws-echo/client/assembly/common/build.sh index 00763725..2652bafb 100644 --- a/examples/echo/ws-echo/client/assembly/common/build.sh +++ b/examples/echo/ws-echo/client/assembly/common/build.sh @@ -15,7 +15,8 @@ PROJECT_HOME=`pwd` TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +#version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +version="1.0" if [[ ${GOOS} == "windows" ]]; then TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe fi @@ -24,12 +25,12 @@ if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 # GFLAGS=-gcflags "-N -l" -race -v # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - else # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - fi TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} diff --git a/examples/echo/ws-echo/server/assembly/common/build.sh b/examples/echo/ws-echo/server/assembly/common/build.sh index 00763725..2652bafb 100644 --- a/examples/echo/ws-echo/server/assembly/common/build.sh +++ b/examples/echo/ws-echo/server/assembly/common/build.sh @@ -15,7 +15,8 @@ PROJECT_HOME=`pwd` TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +#version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +version="1.0" if [[ ${GOOS} == "windows" ]]; then TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe fi @@ -24,12 +25,12 @@ if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 # GFLAGS=-gcflags "-N -l" -race -v # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - else # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - fi TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} diff --git a/examples/echo/wss-echo/client/assembly/common/build.sh b/examples/echo/wss-echo/client/assembly/common/build.sh index 00763725..2652bafb 100644 --- a/examples/echo/wss-echo/client/assembly/common/build.sh +++ b/examples/echo/wss-echo/client/assembly/common/build.sh @@ -15,7 +15,8 @@ PROJECT_HOME=`pwd` TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +#version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +version="1.0" if [[ ${GOOS} == "windows" ]]; then TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe fi @@ -24,12 +25,12 @@ if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 # GFLAGS=-gcflags "-N -l" -race -v # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - else # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - fi TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} diff --git a/examples/echo/wss-echo/server/assembly/common/build.sh b/examples/echo/wss-echo/server/assembly/common/build.sh index 00763725..2652bafb 100644 --- a/examples/echo/wss-echo/server/assembly/common/build.sh +++ b/examples/echo/wss-echo/server/assembly/common/build.sh @@ -15,7 +15,8 @@ PROJECT_HOME=`pwd` TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} TARGET_SBIN_NAME=${TARGET_EXEC_NAME} -version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +#version=`cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +version="1.0" if [[ ${GOOS} == "windows" ]]; then TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe fi @@ -24,12 +25,12 @@ if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then # GFLAGS=-gcflags "-N -l" -race -x -v # -x会把go build的详细过程输出 # GFLAGS=-gcflags "-N -l" -race -v # GFLAGS="-gcflags \"-N -l\" -v" - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - else # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果), # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试, # -w基本没啥损失。-s的损失就有点大了。 - cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - fi TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} diff --git a/go.mod b/go.mod index 1a595e13..c3ab61c4 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,12 @@ module github.com/AlexStocks/getty -go 1.14 +go 1.20 require ( github.com/AlexStocks/goext v0.3.2 - github.com/AlexStocks/log4go v1.0.7 // indirect github.com/dubbogo/gost v1.13.1 - github.com/fatih/camelcase v1.0.0 // indirect - github.com/fatih/structs v1.1.0 // indirect github.com/golang/snappy v0.0.1 github.com/gorilla/websocket v1.4.2 - github.com/juju/errors v0.0.0-20220331221717-b38fca44723b // indirect github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.7.0 @@ -18,3 +14,27 @@ require ( go.uber.org/zap v1.21.0 gopkg.in/yaml.v2 v2.4.0 ) + +require ( + github.com/AlexStocks/log4go v1.0.7 // indirect + github.com/BurntSushi/toml v0.3.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fatih/camelcase v1.0.0 // indirect + github.com/fatih/structs v1.1.0 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/juju/errors v0.0.0-20220331221717-b38fca44723b // indirect + github.com/k0kubun/pp v3.0.1+incompatible // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/mailru/easyjson v0.7.1 // indirect + github.com/mattn/go-colorable v0.0.9 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/shirou/gopsutil/v3 v3.22.2 // indirect + github.com/tklauser/go-sysconf v0.3.10 // indirect + github.com/tklauser/numcpus v0.4.0 // indirect + github.com/yusufpapurcu/wmi v1.2.2 // indirect + go.uber.org/multierr v1.6.0 // indirect + golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect +) diff --git a/go.sum b/go.sum index 9a28a6e3..0b8c6d29 100644 --- a/go.sum +++ b/go.sum @@ -432,7 +432,6 @@ golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -442,7 +441,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -612,7 +610,6 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201014170642-d1624618ad65/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -706,7 +703,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/transport/client.go b/transport/client.go index 4192d12a..71e78611 100644 --- a/transport/client.go +++ b/transport/client.go @@ -22,8 +22,8 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" "net" + "os" "strings" "sync" "sync/atomic" @@ -32,16 +32,11 @@ import ( import ( log "github.com/AlexStocks/getty/util" -) - -import ( - "github.com/dubbogo/gost/bytes" + gxbytes "github.com/dubbogo/gost/bytes" "github.com/dubbogo/gost/net" gxsync "github.com/dubbogo/gost/sync" gxtime "github.com/dubbogo/gost/time" - "github.com/gorilla/websocket" - perrors "github.com/pkg/errors" ) @@ -190,8 +185,8 @@ func (c *client) dialUDP() Session { buf []byte ) - bufp = gxbytes.GetBytes(128) - defer gxbytes.PutBytes(bufp) + bufp = gxbytes.AcquireBytes(128) + defer gxbytes.ReleaseBytes(bufp) buf = *bufp localAddr = &net.UDPAddr{IP: net.IPv4zero, Port: 0} peerAddr, _ = net.ResolveUDPAddr("udp", c.addr) @@ -285,9 +280,9 @@ func (c *client) dialWSS() Session { } if c.cert != "" { - certPEMBlock, err := ioutil.ReadFile(c.cert) + certPEMBlock, err := os.ReadFile(c.cert) if err != nil { - panic(fmt.Sprintf("ioutil.ReadFile(cert:%s) = error:%+v", c.cert, perrors.WithStack(err))) + panic(fmt.Sprintf("os.ReadFile(cert:%s) = error:%+v", c.cert, perrors.WithStack(err))) } var cert tls.Certificate diff --git a/transport/connection.go b/transport/connection.go index 6f46e886..b989f068 100644 --- a/transport/connection.go +++ b/transport/connection.go @@ -268,17 +268,14 @@ func (t *gettyTCPConn) recv(p []byte) (int, error) { // set read timeout deadline if t.compress == CompressNone && t.rTimeout.Load() > 0 { - // Optimization: update read deadline only if more than 25% - // of the last read deadline exceeded. - // See https://github.com/golang/go/issues/15133 for details. + // Set Deadline every time, since golang has fixed the performance issue + // See https://github.com/golang/go/issues/15133#issuecomment-271571395 for details currentTime = time.Now() - if currentTime.Sub(t.rLastDeadline.Load()) > t.rTimeout.Load()>>2 { - if err = t.conn.SetReadDeadline(currentTime.Add(t.rTimeout.Load())); err != nil { - // just a timeout error - return 0, perrors.WithStack(err) - } - t.rLastDeadline.Store(currentTime) + if err = t.conn.SetReadDeadline(currentTime.Add(t.rTimeout.Load())); err != nil { + // just a timeout error + return 0, perrors.WithStack(err) } + t.rLastDeadline.Store(currentTime) } length, err = t.reader.Read(p) @@ -298,16 +295,13 @@ func (t *gettyTCPConn) send(pkg interface{}) (int, error) { ) if t.compress == CompressNone && t.wTimeout.Load() > 0 { - // Optimization: update write deadline only if more than 25% - // of the last write deadline exceeded. - // See https://github.com/golang/go/issues/15133 for details. + // Set Deadline every time, since golang has fixed the performance issue + // See https://github.com/golang/go/issues/15133#issuecomment-271571395 for details currentTime = time.Now() - if currentTime.Sub(t.wLastDeadline.Load()) > t.wTimeout.Load()>>2 { - if err = t.conn.SetWriteDeadline(currentTime.Add(t.wTimeout.Load())); err != nil { - return 0, perrors.WithStack(err) - } - t.wLastDeadline.Store(currentTime) + if err = t.conn.SetWriteDeadline(currentTime.Add(t.wTimeout.Load())); err != nil { + return 0, perrors.WithStack(err) } + t.wLastDeadline.Store(currentTime) } if buffers, ok := pkg.([][]byte); ok { @@ -419,16 +413,13 @@ func (u *gettyUDPConn) SetCompressType(c CompressType) { // udp connection read func (u *gettyUDPConn) recv(p []byte) (int, *net.UDPAddr, error) { if u.rTimeout.Load() > 0 { - // Optimization: update read deadline only if more than 25% - // of the last read deadline exceeded. - // See https://github.com/golang/go/issues/15133 for details. + // Set Deadline every time, since golang has fixed the performance issue + // See https://github.com/golang/go/issues/15133#issuecomment-271571395 for details currentTime := time.Now() - if currentTime.Sub(u.rLastDeadline.Load()) > u.rTimeout.Load()>>2 { - if err := u.conn.SetReadDeadline(currentTime.Add(u.rTimeout.Load())); err != nil { - return 0, nil, perrors.WithStack(err) - } - u.rLastDeadline.Store(currentTime) + if err := u.conn.SetReadDeadline(currentTime.Add(u.rTimeout.Load())); err != nil { + return 0, nil, perrors.WithStack(err) } + u.rLastDeadline.Store(currentTime) } length, addr, err := u.conn.ReadFromUDP(p) // connected udp also can get return @addr @@ -466,16 +457,13 @@ func (u *gettyUDPConn) send(udpCtx interface{}) (int, error) { } if u.wTimeout.Load() > 0 { - // Optimization: update write deadline only if more than 25% - // of the last write deadline exceeded. - // See https://github.com/golang/go/issues/15133 for details. + // Set Deadline every time, since golang has fixed the performance issue + // See https://github.com/golang/go/issues/15133#issuecomment-271571395 for details currentTime = time.Now() - if currentTime.Sub(u.wLastDeadline.Load()) > u.wTimeout.Load()>>2 { - if err = u.conn.SetWriteDeadline(currentTime.Add(u.wTimeout.Load())); err != nil { - return 0, perrors.WithStack(err) - } - u.wLastDeadline.Store(currentTime) + if err = u.conn.SetWriteDeadline(currentTime.Add(u.wTimeout.Load())); err != nil { + return 0, perrors.WithStack(err) } + u.wLastDeadline.Store(currentTime) } if length, _, err = u.conn.WriteMsgUDP(buf, nil, peerAddr); err == nil { @@ -553,7 +541,12 @@ func (w *gettyWSConn) handlePing(message string) error { err := w.writePong([]byte(message)) if err == websocket.ErrCloseSent { err = nil - } else if e, ok := err.(net.Error); ok && e.Temporary() { + + // change the error checking from "e.Temporary()" to "e.Timeout()". + // as per https://github.com/golang/go/issues/45729, + // Timeout() correctly captures subset of Temporary() errors that could be retried. + // The rest of Temporary() errors should not be retried anyway (like syscall errors, out of file descriptors) + } else if e, ok := err.(net.Error); ok && e.Timeout() { err = nil } if err == nil { @@ -591,16 +584,13 @@ func (w *gettyWSConn) updateWriteDeadline() error { ) if w.wTimeout.Load() > 0 { - // Optimization: update write deadline only if more than 25% - // of the last write deadline exceeded. - // See https://github.com/golang/go/issues/15133 for details. + // Set Deadline every time, since golang has fixed the performance issue + // See https://github.com/golang/go/issues/15133#issuecomment-271571395 for details currentTime = time.Now() - if currentTime.Sub(w.wLastDeadline.Load()) > w.wTimeout.Load()>>2 { - if err = w.conn.SetWriteDeadline(currentTime.Add(w.wTimeout.Load())); err != nil { - return perrors.WithStack(err) - } - w.wLastDeadline.Store(currentTime) + if err = w.conn.SetWriteDeadline(currentTime.Add(w.wTimeout.Load())); err != nil { + return perrors.WithStack(err) } + w.wLastDeadline.Store(currentTime) } return nil diff --git a/transport/server.go b/transport/server.go index 6c9c641c..be4286c1 100644 --- a/transport/server.go +++ b/transport/server.go @@ -22,9 +22,9 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" "net" "net/http" + "os" "strings" "sync" "time" @@ -300,7 +300,11 @@ func (s *server) runTCPEventLoop(newSession NewSessionCallback) { } client, err = s.accept(newSession) if err != nil { - if netErr, ok := perrors.Cause(err).(net.Error); ok && netErr.Temporary() { + // change the error checking from "netErr.Temporary()" to "netErr.Timeout()". + // as per https://github.com/golang/go/issues/45729, + // Timeout() correctly captures subset of Temporary() errors that could be retried. + // The rest of Temporary() errors should not be retried anyway (like syscall errors, out of file descriptors) + if netErr, ok := perrors.Cause(err).(net.Error); ok && netErr.Timeout() { if delay == 0 { delay = 5 * time.Millisecond } else { @@ -453,9 +457,9 @@ func (s *server) runWSSEventLoop(newSession NewSessionCallback) { } if s.caCert != "" { - certPem, err = ioutil.ReadFile(s.caCert) + certPem, err = os.ReadFile(s.caCert) if err != nil { - panic(fmt.Errorf("ioutil.ReadFile(certFile{%s}) = err:%+v", s.caCert, perrors.WithStack(err))) + panic(fmt.Errorf("os.ReadFile(certFile{%s}) = err:%+v", s.caCert, perrors.WithStack(err))) } certPool = x509.NewCertPool() if ok := certPool.AppendCertsFromPEM(certPem); !ok { diff --git a/transport/session.go b/transport/session.go index ee971a47..8d585aa5 100644 --- a/transport/session.go +++ b/transport/session.go @@ -20,23 +20,21 @@ package getty import ( "bytes" "context" + "crypto/tls" "fmt" "io" "net" "runtime" "sync" "time" -) -import ( log "github.com/AlexStocks/getty/util" -) -import ( gxbytes "github.com/dubbogo/gost/bytes" + gxcontext "github.com/dubbogo/gost/context" - gxtime "github.com/dubbogo/gost/time" + gxtime "github.com/dubbogo/gost/time" "github.com/gorilla/websocket" perrors "github.com/pkg/errors" @@ -53,6 +51,8 @@ const ( MaxWheelTimeSpan = 900e9 maxPacketLen = 16 * 1024 + defaultTLSHandshakeTimeout = time.Second * 3 + defaultSessionName = "session" defaultTCPSessionName = "tcp-session" defaultUDPSessionName = "udp-session" @@ -566,6 +566,12 @@ func (s *session) run() { func (s *session) addTask(pkg interface{}) { f := func() { + // If the session is closed, there is no need to perform CPU-intensive operations. + if s.IsClosed() { + log.Errorf("[Id:%d, name=%s, endpoint=%s] Session is closed", s.ID(), s.name, s.EndPoint()) + return + } + s.listener.OnMessage(s, pkg) s.incReadPkgNum() } @@ -635,6 +641,18 @@ func (s *session) handleTCPPackage() error { pktBuf = gxbytes.NewBuffer(nil) conn = s.Connection.(*gettyTCPConn) + if tlsConn, ok := conn.conn.(*tls.Conn); ok { + tlsHandshaketime := defaultTLSHandshakeTimeout + if s.readTimeout() > 0 { + tlsHandshaketime = s.readTimeout() + } + ctx, cancel := context.WithTimeout(context.Background(), tlsHandshaketime) + defer cancel() + if err := tlsConn.HandshakeContext(ctx); err != nil { + log.Errorf("[tlsConn.HandshakeContext] = error:%+v", err) + return perrors.Wrap(err, "tlsConn.HandshakeContext") + } + } for { if s.IsClosed() { err = nil diff --git a/transport/tls.go b/transport/tls.go index d736ed90..4fec026a 100644 --- a/transport/tls.go +++ b/transport/tls.go @@ -21,7 +21,7 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "io/ioutil" + "os" ) import ( @@ -66,9 +66,9 @@ func (s *ServerTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) { } if s.ServerTrustCertCollectionPath != "" { - certPem, err = ioutil.ReadFile(s.ServerTrustCertCollectionPath) + certPem, err = os.ReadFile(s.ServerTrustCertCollectionPath) if err != nil { - log.Error(fmt.Errorf("ioutil.ReadFile(certFile{%s}) = err:%+v", s.ServerTrustCertCollectionPath, perrors.WithStack(err))) + log.Error(fmt.Errorf("os.ReadFile(certFile{%s}) = err:%+v", s.ServerTrustCertCollectionPath, perrors.WithStack(err))) return nil, err } certPool = x509.NewCertPool() @@ -98,7 +98,7 @@ func (c *ClientTlsConfigBuilder) BuildTlsConfig() (*tls.Config, error) { log.Error(fmt.Sprintf("Unable to load X509 Key Pair %v", err)) return nil, err } - certBytes, err := ioutil.ReadFile(c.ClientTrustCertCollectionPath) + certBytes, err := os.ReadFile(c.ClientTrustCertCollectionPath) if err != nil { log.Error(fmt.Sprintf("Unable to read pem file: %s", c.ClientTrustCertCollectionPath)) return nil, err