chore: add Windows backend startup script
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
@echo off
|
||||
setlocal EnableExtensions DisableDelayedExpansion
|
||||
|
||||
set "PROJECT_ROOT=%~dp0"
|
||||
set "BACKEND_ROOT=%PROJECT_ROOT%backend-api"
|
||||
|
||||
if not "%~1"=="" if /i not "%~1"=="--migrate" (
|
||||
echo Usage: %~nx0 [--migrate]
|
||||
echo --migrate Apply pending database migrations before starting the API.
|
||||
exit /b 2
|
||||
)
|
||||
|
||||
if not exist "%BACKEND_ROOT%\go.mod" (
|
||||
echo Missing backend project: "%BACKEND_ROOT%"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
where go >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
echo Go 1.23.0 is required but was not found on PATH.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set "GOTOOLCHAIN=local"
|
||||
set "CGO_ENABLED=1"
|
||||
for /f "tokens=3" %%G in ('go version') do set "GO_VERSION=%%G"
|
||||
if /i not "%GO_VERSION%"=="go1.23.0" (
|
||||
echo Go 1.23.0 is required. Current version: %GO_VERSION%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
where gcc >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
echo GCC is required because the SQLite driver uses CGO.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
pushd "%BACKEND_ROOT%"
|
||||
if errorlevel 1 (
|
||||
echo Cannot enter backend directory: "%BACKEND_ROOT%"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if not exist "var" mkdir "var"
|
||||
if errorlevel 1 goto :startup_failed
|
||||
if not exist "var\assets" mkdir "var\assets"
|
||||
if errorlevel 1 goto :startup_failed
|
||||
|
||||
if /i "%~1"=="--migrate" (
|
||||
echo Applying database migrations...
|
||||
go run ./cmd/migrate up
|
||||
if errorlevel 1 goto :startup_failed
|
||||
)
|
||||
|
||||
if defined CMROUBAO_HTTP_ADDR (
|
||||
echo Starting cmroubao backend with configured CMROUBAO_HTTP_ADDR...
|
||||
) else (
|
||||
echo Starting cmroubao backend at 127.0.0.1:8080...
|
||||
)
|
||||
echo Press Ctrl+C to stop.
|
||||
go run ./cmd/api
|
||||
set "EXIT_CODE=%ERRORLEVEL%"
|
||||
popd
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:startup_failed
|
||||
set "EXIT_CODE=%ERRORLEVEL%"
|
||||
if "%EXIT_CODE%"=="0" set "EXIT_CODE=1"
|
||||
popd
|
||||
exit /b %EXIT_CODE%
|
||||
Reference in New Issue
Block a user