Files
niumalll/go-backend/start_dev.sh

46 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 本地开发启动脚本
echo "正在启动NiūMall Go后端开发环境..."
# 检查是否安装了Go
if ! command -v go &> /dev/null
then
echo "未检测到Go环境请先安装Go 1.21或更高版本"
exit 1
fi
# 检查是否安装了Docker
if ! command -v docker &> /dev/null
then
echo "未检测到Docker请先安装Docker"
exit 1
fi
# 检查是否安装了docker-compose
if ! command -v docker-compose &> /dev/null
then
echo "未检测到docker-compose请先安装docker-compose"
exit 1
fi
# 设置环境变量
export DB_HOST=localhost
export DB_PORT=3306
export DB_USER=root
export DB_PASSWORD=
export DB_NAME=niumall_dev
export PORT=8080
export GIN_MODE=debug
export JWT_SECRET=mysecretkey
# 创建开发数据库(如果不存在)
echo "正在创建开发数据库..."
mysql -h$DB_HOST -P$DB_PORT -u$DB_USER -p$DB_PASSWORD -e "CREATE DATABASE IF NOT EXISTS $DB_NAME;" 2>/dev/null || {
echo "警告无法创建数据库请确保MySQL服务正在运行且凭据正确"
}
# 启动Go应用
echo "正在启动Go应用..."
go run main.go