feat(backend): establish gin sqlite service skeleton

This commit is contained in:
QiuSW
2026-07-25 22:29:56 +08:00
parent 84f2da3cf7
commit ab21219a07
32 changed files with 1854 additions and 42 deletions
+46
View File
@@ -12,6 +12,7 @@ $sdkRoot = if ($env:ANDROID_SDK_ROOT) {
}
$gradle = Join-Path $PSScriptRoot "android-buyer\gradlew.bat"
$backendRoot = Join-Path $PSScriptRoot "backend-api"
$adb = Join-Path $sdkRoot "platform-tools\adb.exe"
$apk = Join-Path $PSScriptRoot "android-buyer\app\build\outputs\apk\debug\app-debug.apk"
@@ -31,9 +32,26 @@ $javaVersion = (& java -version 2>&1) -join "`n"
if ($javaVersion -notmatch 'version "17(?:\.|")') {
throw "需要 JDK 17,当前 java -version 输出: $javaVersion"
}
if (-not (Test-Path -LiteralPath (Join-Path $backendRoot "go.mod"))) {
throw "缺少 Go 后端工程: $backendRoot"
}
if (-not (Get-Command go -ErrorAction SilentlyContinue)) {
throw "缺少 Go 1.23.0,go 不在 PATH 中。"
}
$goVersion = (& go version) -join "`n"
if ($goVersion -notmatch '\bgo1\.23\.0\b') {
throw "需要 Go 1.23.0,当前 go version 输出: $goVersion"
}
if (-not (Get-Command gcc -ErrorAction SilentlyContinue)) {
throw "SQLite CGO 构建需要 GCC,gcc 不在 PATH 中。"
}
$env:ANDROID_HOME = $sdkRoot
$env:ANDROID_SDK_ROOT = $sdkRoot
$env:GOTOOLCHAIN = "local"
if ((& go env CGO_ENABLED) -ne "1") {
throw "SQLite 构建需要 CGO_ENABLED=1。"
}
Write-Host "==> 验证 Android 工程"
Push-Location (Join-Path $PSScriptRoot "android-buyer")
@@ -48,6 +66,34 @@ try {
Write-Host "==> Debug APK: $apk"
Write-Host "==> 验证 Go 后端"
Push-Location $backendRoot
try {
& go test ./...
if ($LASTEXITCODE -ne 0) {
throw "Go 后端测试失败,退出码: $LASTEXITCODE"
}
& go vet ./...
if ($LASTEXITCODE -ne 0) {
throw "Go 后端 vet 失败,退出码: $LASTEXITCODE"
}
$unformatted = @(& gofmt -l cmd internal migrations)
if ($LASTEXITCODE -ne 0 -or $unformatted.Count -ne 0) {
throw "Go 后端存在未格式化文件: $($unformatted -join ', ')"
}
New-Item -ItemType Directory -Force "bin" | Out-Null
& go build -o "bin/cmroubao-api.exe" ./cmd/api
if ($LASTEXITCODE -ne 0) {
throw "Go API 构建失败,退出码: $LASTEXITCODE"
}
& go build -o "bin/cmroubao-migrate.exe" ./cmd/migrate
if ($LASTEXITCODE -ne 0) {
throw "Go migration 构建失败,退出码: $LASTEXITCODE"
}
} finally {
Pop-Location
}
if ($env:RUN_START_COMMAND -eq "1") {
if (-not (Test-Path -LiteralPath $adb)) {
throw "缺少 SDK Platform Tools: $adb"