Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:go编译选项去掉-i,新增version文件 #3

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions echo/tcp-echo/client/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
*****************************************************
# DESC : echo stream parser
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : [email protected]
# MOD : 2016-09-04 13:08
# FILE : readwriter.go
*****************************************************
*/

package main

var (
Version = "1.0.0"
)
13 changes: 6 additions & 7 deletions echo/tcp-echo/client/assembly/common/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@

rm -rf target/

PROJECT_HOME=`pwd`
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}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Missing version.go file in expected location

The build script is looking for version.go in the app directory relative to where the build script is executed, but this file doesn't exist in the expected location. The directory structure shows that version.go files exist in other locations:

  • micro/client/app/version.go
  • micro/server/app/version.go
  • rpc/client/app/version.go
  • rpc/server/app/version.go

The build script needs to be updated to use the correct path to version.go or the file needs to be created in the expected location.

🔗 Analysis chain

Verify version.go file existence

Since the build script relies on reading the version from app/version.go, let's verify its existence and content.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify version.go exists and has correct format
if [[ -f "app/version.go" ]]; then
    echo "version.go exists"
    cat "app/version.go"
else
    echo "Error: version.go not found"
    # Search for version.go in nearby directories
    fd --type f "version.go" --max-depth 3
fi

Length of output: 129


Script:

#!/bin/bash
# Let's check the actual directory structure and content of the build.sh file
echo "=== Directory structure ==="
fd --type f --max-depth 4

echo -e "\n=== Content of build.sh ==="
cat "echo/tcp-echo/client/assembly/common/build.sh"

Length of output: 8121

if [[ ${GOOS} == "windows" ]]; then
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe
fi
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME}
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then
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 -
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for directory changes

The cd commands should handle potential failures to prevent script from continuing in wrong directory.

Apply these changes:

-    cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+    cd ${BUILD_PACKAGE} || exit 1
+    GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME}
+    cd - || exit 1

-    cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd -
+    cd ${BUILD_PACKAGE} || exit 1
+    GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME}
+    cd - || exit 1

Also applies to: 32-32

🧰 Tools
🪛 Shellcheck

[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

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}
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE}

mkdir -p ${TARGET_FOLDER}/${TAR_NAME}

Expand Down Expand Up @@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR}
cd ${TARGET_FOLDER}

tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/*

16 changes: 16 additions & 0 deletions echo/tcp-echo/server/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
*****************************************************
# DESC : echo stream parser
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : [email protected]
# MOD : 2016-09-04 13:08
# FILE : readwriter.go
*****************************************************
*/

package main

var (
Version = "1.0.0"
)
13 changes: 6 additions & 7 deletions echo/tcp-echo/server/assembly/common/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@

rm -rf target/

PROJECT_HOME=`pwd`
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}')
if [[ ${GOOS} == "windows" ]]; then
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe
fi
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME}
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then
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 -
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for cd commands

The cd commands should handle potential failures to prevent script from continuing in an incorrect directory.

Apply these changes:

-    cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+    cd ${BUILD_PACKAGE} || exit 1
+    GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME}
+    cd - || exit 1

-    cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd -
+    cd ${BUILD_PACKAGE} || exit 1
+    GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME}
+    cd - || exit 1

Also applies to: 32-32

🧰 Tools
🪛 Shellcheck

[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

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}
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE}

mkdir -p ${TARGET_FOLDER}/${TAR_NAME}

Expand Down Expand Up @@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR}
cd ${TARGET_FOLDER}

tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/*

16 changes: 16 additions & 0 deletions echo/udp-echo/client/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
*****************************************************
# DESC : echo stream parser
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : [email protected]
# MOD : 2016-09-04 13:08
# FILE : readwriter.go
*****************************************************
*/

package main

var (
Version = "1.0.0"
)
13 changes: 6 additions & 7 deletions echo/udp-echo/client/assembly/common/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@

rm -rf target/

PROJECT_HOME=`pwd`
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}')
if [[ ${GOOS} == "windows" ]]; then
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe
fi
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME}
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then
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 -
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for directory changes

The current cd commands could fail silently, potentially causing unexpected behavior.

Add error handling:

-cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+cd ${BUILD_PACKAGE} || exit 1; GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - || exit 1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
cd ${BUILD_PACKAGE} || exit 1; GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - || exit 1
🧰 Tools
🪛 Shellcheck

[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

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 -
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for directory changes

Similar to the development build command, this cd command needs error handling.

Add error handling:

-cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd -
+cd ${BUILD_PACKAGE} || exit 1; GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - || exit 1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd -
cd ${BUILD_PACKAGE} || exit 1; GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd - || exit 1
🧰 Tools
🪛 Shellcheck

[warning] 32-32: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

fi

TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE}
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE}

mkdir -p ${TARGET_FOLDER}/${TAR_NAME}

Expand Down Expand Up @@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR}
cd ${TARGET_FOLDER}

tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/*

16 changes: 16 additions & 0 deletions echo/udp-echo/server/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
*****************************************************
# DESC : echo stream parser
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : [email protected]
# MOD : 2016-09-04 13:08
# FILE : readwriter.go
*****************************************************
*/
Comment on lines +1 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

File header comment needs to be updated

The current file header contains incorrect information:

  • Filename is listed as "readwriter.go" instead of "version.go"
  • Description mentions "echo stream parser" which doesn't match the file's purpose
  • Modification date (2016-09-04) appears to be outdated

Apply this diff to fix the header:

 /*
 *****************************************************
-# DESC    : echo stream parser
+# DESC    : Version information for UDP echo server
 # AUTHOR  : Alex Stocks
 # LICENCE : Apache License 2.0
 # EMAIL   : [email protected]
-# MOD     : 2016-09-04 13:08
-# FILE    : readwriter.go
+# MOD     : 2024-11-xx xx:xx
+# FILE    : version.go
 *****************************************************
 */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/*
*****************************************************
# DESC : echo stream parser
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-09-04 13:08
# FILE : readwriter.go
*****************************************************
*/
/*
*****************************************************
# DESC : Version information for UDP echo server
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2024-11-xx xx:xx
# FILE : version.go
*****************************************************
*/


package main

var (
Version = "1.0.0"
)
13 changes: 6 additions & 7 deletions echo/udp-echo/server/assembly/common/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@

rm -rf target/

PROJECT_HOME=`pwd`
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}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make version extraction more robust

The current version extraction method is fragile and could fail silently if the format of version.go changes. Consider adding error handling and using a more reliable parsing method.

-version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
+if [ ! -f "app/version.go" ]; then
+    echo "Error: version.go not found"
+    exit 1
+fi
+version=$(grep -Po 'Version = "\K[^"]*' app/version.go)
+if [ -z "$version" ]; then
+    echo "Error: Could not extract version"
+    exit 1
+fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
if [ ! -f "app/version.go" ]; then
echo "Error: version.go not found"
exit 1
fi
version=$(grep -Po 'Version = "\K[^"]*' app/version.go)
if [ -z "$version" ]; then
echo "Error: Could not extract version"
exit 1
fi

if [[ ${GOOS} == "windows" ]]; then
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe
fi
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME}
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then
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}
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE}

mkdir -p ${TARGET_FOLDER}/${TAR_NAME}

Expand Down Expand Up @@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR}
cd ${TARGET_FOLDER}

tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/*

16 changes: 16 additions & 0 deletions echo/ws-echo/client/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
*****************************************************
# DESC : echo stream parser
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : [email protected]
# MOD : 2016-09-04 13:08
# FILE : readwriter.go
*****************************************************
*/

package main

var (
Version = "1.0.0"
)
13 changes: 6 additions & 7 deletions echo/ws-echo/client/assembly/common/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@

rm -rf target/

PROJECT_HOME=`pwd`
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}')
if [[ ${GOOS} == "windows" ]]; then
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe
fi
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME}
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then
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}
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE}

mkdir -p ${TARGET_FOLDER}/${TAR_NAME}

Expand Down Expand Up @@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR}
cd ${TARGET_FOLDER}

tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/*

16 changes: 16 additions & 0 deletions echo/ws-echo/server/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
*****************************************************
# DESC : echo stream parser
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : [email protected]
# MOD : 2016-09-04 13:08
# FILE : readwriter.go
*****************************************************
*/

package main

var (
Version = "1.0.0"
)
13 changes: 6 additions & 7 deletions echo/ws-echo/server/assembly/common/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@

rm -rf target/

PROJECT_HOME=`pwd`
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}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for version extraction

The version extraction assumes app/version.go exists and contains a specific format. Consider adding error handling to gracefully handle cases where the file is missing or malformed.

-version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
+if [ ! -f app/version.go ]; then
+    echo "Error: app/version.go not found"
+    exit 1
+fi
+version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
+if [ -z "$version" ]; then
+    echo "Error: Failed to extract version from app/version.go"
+    exit 1
+fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
if [ ! -f app/version.go ]; then
echo "Error: app/version.go not found"
exit 1
fi
version=$(cat app/version.go | grep Version | awk -F '=' '{print $2}' | awk -F '"' '{print $2}')
if [ -z "$version" ]; then
echo "Error: Failed to extract version from app/version.go"
exit 1
fi

if [[ ${GOOS} == "windows" ]]; then
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe
fi
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME}
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then
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 -
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for directory changes

The cd commands should handle failures to prevent the script from continuing in the wrong directory.

-    cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+    cd ${BUILD_PACKAGE} || exit 1
+    GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME}
+    cd - || exit 1

-    cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME} && cd -
+    cd ${BUILD_PACKAGE} || exit 1
+    GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -o ${TARGET_NAME}
+    cd - || exit 1

Also applies to: 32-32

🧰 Tools
🪛 Shellcheck

[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

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}
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation for required environment variables

The script uses several environment variables (GOOS, GOARCH, PROFILE, TARGET_EXEC_NAME) but doesn't validate their presence. Consider adding validation at the start of the script.

+# Add at the beginning of the script
+required_vars=("GOOS" "GOARCH" "PROFILE" "TARGET_EXEC_NAME" "BUILD_PACKAGE")
+for var in "${required_vars[@]}"; do
+    if [ -z "${!var}" ]; then
+        echo "Error: Required environment variable $var is not set"
+        exit 1
+    fi
+done

Committable suggestion skipped: line range outside the PR's diff.


mkdir -p ${TARGET_FOLDER}/${TAR_NAME}

Expand Down Expand Up @@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR}
cd ${TARGET_FOLDER}

tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/*

16 changes: 16 additions & 0 deletions echo/wss-echo/client/app/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
*****************************************************
# DESC : echo stream parser
# AUTHOR : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : [email protected]
# MOD : 2016-09-04 13:08
# FILE : readwriter.go
*****************************************************
*/

package main

var (
Version = "1.0.0"
)
13 changes: 6 additions & 7 deletions echo/wss-echo/client/assembly/common/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@

rm -rf target/

PROJECT_HOME=`pwd`
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}')
if [[ ${GOOS} == "windows" ]]; then
TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe
fi
TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME}
if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then
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 -
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for directory changes

The cd commands could fail silently, potentially causing unexpected behavior.

Apply this fix to both lines:

-    cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd -
+    cd ${BUILD_PACKAGE} || exit 1; GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -o ${TARGET_NAME} && cd - || exit 1

Also applies to: 32-32

🧰 Tools
🪛 Shellcheck

[warning] 27-27: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

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}
TAR_NAME=${TARGET_EXEC_NAME}-${version}-$(date "+%Y%m%d-%H%M")-${PROFILE}

mkdir -p ${TARGET_FOLDER}/${TAR_NAME}

Expand Down Expand Up @@ -74,4 +74,3 @@ cp -r profiles/${PROFILE}/* ${CONF_DIR}
cd ${TARGET_FOLDER}

tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/*

Loading