编译 Go 应用程序
go build -ldflags="-s -w" -o myapp.exe .
使用 UPX 压缩可执行文件(window下载并设置环境变量)
upx --best --lzma myapp.exe
可从10M压缩到1M
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | @echo off REM Set Go environment variables set CGO_ENABLED=0 set GOOS=linux set GOARCH=arm set GOARM=7 REM Compile the Go program echo Compiling Go program... go build -ldflags "-s -w" REM Check if the compilation was successful IF ERRORLEVEL 1 ( echo Compilation failed, please check the code. pause exit /B 1 ) echo Compilation successful, packing files... REM Use 7-Zip to package files "C:\Program Files\7-Zip\7z.exe" a bin\tboxconfig_arm7.tar tboxconfig wwwroot config.json IF ERRORLEVEL 1 ( echo Packaging failed, please check if the folder and files exist. pause exit /B 1 ) echo Packaging successful, generated file is tboxconfig_arm7.zip pause exit /B 0 |