mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-06 21:32:15 +08:00
mage
This commit is contained in:
parent
220eeca866
commit
8ff5c89001
31
bootstrap.bat
Normal file
31
bootstrap.bat
Normal file
@ -0,0 +1,31 @@
|
||||
@echo off
|
||||
SETLOCAL
|
||||
|
||||
mage -version >nul 2>&1
|
||||
IF %ERRORLEVEL% EQU 0 (
|
||||
echo Mage is already installed.
|
||||
GOTO DOWNLOAD
|
||||
)
|
||||
|
||||
go version >nul 2>&1
|
||||
IF NOT %ERRORLEVEL% EQU 0 (
|
||||
echo Go is not installed. Please install Go and try again.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Installing Mage...
|
||||
go install github.com/magefile/mage@latest
|
||||
|
||||
mage -version >nul 2>&1
|
||||
IF NOT %ERRORLEVEL% EQU 0 (
|
||||
echo Mage installation failed.
|
||||
echo Please ensure that %GOPATH%/bin is in your PATH.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Mage installed successfully.
|
||||
|
||||
:DOWNLOAD
|
||||
go mod download
|
||||
|
||||
ENDLOCAL
|
||||
23
bootstrap.sh
Normal file
23
bootstrap.sh
Normal file
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ ":$PATH:" == *":$HOME/.local/bin:"* ]]; then
|
||||
TARGET_DIR="$HOME/.local/bin"
|
||||
else
|
||||
TARGET_DIR="/usr/local/bin"
|
||||
echo "Using /usr/local/bin as the installation directory. Might require sudo permissions."
|
||||
fi
|
||||
|
||||
if ! command -v mage &> /dev/null; then
|
||||
echo "Installing Mage to $TARGET_DIR ..."
|
||||
GOBIN=$TARGET_DIR go install github.com/magefile/mage@latest
|
||||
fi
|
||||
|
||||
if ! command -v mage &> /dev/null; then
|
||||
echo "Mage installation failed."
|
||||
echo "Please ensure that $TARGET_DIR is in your \$PATH."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Mage installed successfully."
|
||||
|
||||
go mod download
|
||||
8
go.mod
8
go.mod
@ -15,7 +15,7 @@ require (
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
github.com/openimsdk/localcache v0.0.1
|
||||
github.com/openimsdk/protocol v0.0.60
|
||||
github.com/openimsdk/tools v0.0.47-alpha.11
|
||||
github.com/openimsdk/tools v0.0.47-alpha.14
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/prometheus/client_golang v1.18.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
@ -33,6 +33,7 @@ require (
|
||||
github.com/go-redis/redis v6.15.9+incompatible
|
||||
github.com/redis/go-redis/v9 v9.4.0
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||
github.com/spf13/viper v1.18.2
|
||||
github.com/stathat/consistent v1.0.0
|
||||
golang.org/x/sync v0.6.0
|
||||
@ -65,6 +66,7 @@ require (
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-logr/logr v1.4.1 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-zookeeper/zk v1.0.3 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
@ -94,6 +96,7 @@ require (
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/lithammer/shortuuid v3.0.0+incompatible // indirect
|
||||
github.com/magefile/mage v1.15.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
@ -122,11 +125,14 @@ require (
|
||||
github.com/stretchr/objx v0.5.0 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.47 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.13 // indirect
|
||||
github.com/tklauser/numcpus v0.7.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.1.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
|
||||
|
||||
17
go.sum
17
go.sum
@ -92,6 +92,8 @@ github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
|
||||
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
@ -225,6 +227,8 @@ github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205Ah
|
||||
github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw=
|
||||
github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w=
|
||||
github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w=
|
||||
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
|
||||
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
@ -266,8 +270,8 @@ github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
github.com/openimsdk/protocol v0.0.60 h1:iz5ORGpGupkaygLTdODogUb3E4jJzSixIXMJiRkc1qs=
|
||||
github.com/openimsdk/protocol v0.0.60/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
|
||||
github.com/openimsdk/tools v0.0.47-alpha.11 h1:VioqYz2zPjoOalvdy63Ryjqnp9cwpP1p2oOoej+pbdI=
|
||||
github.com/openimsdk/tools v0.0.47-alpha.11/go.mod h1:aTh3aPbr4bibBGf0qnC3nTWC947xFOrvHsW6WZ1oV3E=
|
||||
github.com/openimsdk/tools v0.0.47-alpha.14 h1:ueFwzYmWxwqCq5WU5vi3pPoBhsFWbrFqUjlffX96j5k=
|
||||
github.com/openimsdk/tools v0.0.47-alpha.14/go.mod h1:aTh3aPbr4bibBGf0qnC3nTWC947xFOrvHsW6WZ1oV3E=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
|
||||
@ -301,6 +305,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
|
||||
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
|
||||
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
|
||||
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
|
||||
@ -334,6 +340,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.563/go.mod
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563/go.mod h1:uom4Nvi9W+Qkom0exYiJ9VWJjXwyxtPYTkKkaLMlfE0=
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.47 h1:uoS4Sob16qEYoapkqJq1D1Vnsy9ira9BfNUMtoFYTI4=
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.47/go.mod h1:DH9US8nB+AJXqwu/AMOrCFN1COv3dpytXuJWHgdg7kE=
|
||||
github.com/tklauser/go-sysconf v0.3.13 h1:GBUpcahXSpR2xN01jhkNAbTLRk2Yzgggk8IM08lq3r4=
|
||||
github.com/tklauser/go-sysconf v0.3.13/go.mod h1:zwleP4Q4OehZHGn4CYZDipCgg9usW5IJePewFCGVEa0=
|
||||
github.com/tklauser/numcpus v0.7.0 h1:yjuerZP127QG9m5Zh/mSO4wqurYil27tHrqwRoRjpr4=
|
||||
github.com/tklauser/numcpus v0.7.0/go.mod h1:bb6dMVcj8A42tSE7i32fsIUCbQNllK5iDguyOZRUzAY=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
@ -349,6 +359,8 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7Jul
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
|
||||
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
@ -429,6 +441,7 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
||||
38
magefile.go
Normal file
38
magefile.go
Normal file
@ -0,0 +1,38 @@
|
||||
//go:build mage
|
||||
// +build mage
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/tools/utils/mageutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Default = Build
|
||||
|
||||
func Build() {
|
||||
platforms := os.Getenv("PLATFORMS")
|
||||
if platforms == "" {
|
||||
platforms = mageutil.DetectPlatform()
|
||||
}
|
||||
|
||||
for _, platform := range strings.Split(platforms, " ") {
|
||||
mageutil.CompileForPlatform(platform)
|
||||
}
|
||||
|
||||
mageutil.PrintGreen("Compilation complete.")
|
||||
}
|
||||
|
||||
func Start() {
|
||||
setMaxOpenFiles()
|
||||
mageutil.StartToolsAndServices()
|
||||
}
|
||||
|
||||
func Stop() {
|
||||
mageutil.StopAndCheckBinaries()
|
||||
}
|
||||
|
||||
func Check() {
|
||||
mageutil.CheckAndReportBinariesStatus()
|
||||
}
|
||||
20
magefile_unix.go
Normal file
20
magefile_unix.go
Normal file
@ -0,0 +1,20 @@
|
||||
//go:build mage && !windows
|
||||
// +build mage,!windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/tools/utils/mageutil"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func setMaxOpenFiles() error {
|
||||
var rLimit syscall.Rlimit
|
||||
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rLimit.Max = uint64(mageutil.MaxFileDescriptors)
|
||||
rLimit.Cur = uint64(mageutil.MaxFileDescriptors)
|
||||
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||
}
|
||||
8
magefile_windows.go
Normal file
8
magefile_windows.go
Normal file
@ -0,0 +1,8 @@
|
||||
//go:build mage
|
||||
// +build mage
|
||||
|
||||
package main
|
||||
|
||||
func setMaxOpenFiles() error {
|
||||
return nil
|
||||
}
|
||||
70
scripts-new/compile.sh
Normal file
70
scripts-new/compile.sh
Normal file
@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 获取当前目录的绝对路径
|
||||
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)
|
||||
|
||||
# 定义输出目录的基础部分
|
||||
OUTPUT_BASE="${ROOT_DIR}/_output/bin/platforms"
|
||||
|
||||
compile_for_platform() {
|
||||
local platform=$1
|
||||
local os=${platform%_*}
|
||||
local arch=${platform#*_}
|
||||
|
||||
# 最终输出目录
|
||||
OUTPUT_DIR="${OUTPUT_BASE}/${os}/${arch}"
|
||||
|
||||
# 创建输出目录(如果不存在)
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
compile_dir() {
|
||||
for dir in $1/*; do
|
||||
if [ -d "$dir" ] && [ -f "$dir/main.go" ]; then
|
||||
# 获取目录名
|
||||
DIR_NAME=$(basename "$dir")
|
||||
echo "Compiling $DIR_NAME for $platform..."
|
||||
|
||||
# 编译生成二进制文件
|
||||
GOOS=$os GOARCH=$arch go build -o "${OUTPUT_DIR}/${DIR_NAME}" "$dir/main.go"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to compile $DIR_NAME for $platform"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
echo "Compiling cmd for $platform..."
|
||||
compile_dir "${ROOT_DIR}/cmd"
|
||||
|
||||
echo "Compiling tools for $platform..."
|
||||
compile_dir "${ROOT_DIR}/tools"
|
||||
}
|
||||
|
||||
# 检测并编译指定的平台
|
||||
if [ -z "$PLATFORMS" ]; then
|
||||
# 默认使用当前系统的平台
|
||||
OS=$(uname | tr '[:upper:]' '[:lower:]')
|
||||
ARCH=$(uname -m)
|
||||
case $ARCH in
|
||||
x86_64)
|
||||
ARCH="amd64"
|
||||
;;
|
||||
aarch64)
|
||||
ARCH="arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
compile_for_platform "${OS}_${ARCH}"
|
||||
else
|
||||
# 遍历并编译每个指定的平台
|
||||
IFS=' ' read -ra ADDR <<< "$PLATFORMS"
|
||||
for platform in "${ADDR[@]}"; do
|
||||
compile_for_platform $platform
|
||||
done
|
||||
fi
|
||||
|
||||
echo "Compilation complete. Binaries are located in ${OUTPUT_BASE}"
|
||||
8
start-config.yml
Normal file
8
start-config.yml
Normal file
@ -0,0 +1,8 @@
|
||||
binaries:
|
||||
openim-no-port: 1
|
||||
openim-test: 1
|
||||
|
||||
toolBinaries:
|
||||
- check-free-memory
|
||||
|
||||
maxFileDescriptors: 100000
|
||||
@ -2,25 +2,24 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var sysInfo syscall.Sysinfo_t
|
||||
|
||||
err := syscall.Sysinfo(&sysInfo)
|
||||
// 使用gopsutil获取虚拟内存信息
|
||||
vMem, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to get system info: %v\n", err)
|
||||
os.Exit(-1)
|
||||
fmt.Fprintf(os.Stderr, "Failed to get virtual memory info: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Sysinfo returns memory in bytes, convert it to gigabytes
|
||||
freeMemoryGB := float64(sysInfo.Freeram) / float64(1024*1024*1024)
|
||||
// 将可用内存从字节转换为GB
|
||||
freeMemoryGB := float64(vMem.Free) / float64(1024*1024*1024)
|
||||
|
||||
if freeMemoryGB < 4.0 {
|
||||
fmt.Fprintf(os.Stderr, "System free memory is less than 4GB: %.2fGB\n", freeMemoryGB)
|
||||
os.Exit(-1)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Printf("System free memory is sufficient: %.2fGB\n", freeMemoryGB)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user