跳转至

快速开始指南

通过本快速开始指南,在几分钟内启动并运行 R Commerce。

前提条件

在开始之前,请确保已安装以下软件:

安装

选项 1:从源码构建

# 克隆仓库
git clone https://github.com/creativebastard/rcommerce.git
cd gocart

# 构建项目
cargo build --release

# 二进制文件将位于:
# target/release/rcommerce

选项 2:Docker(快速开始推荐)

# 克隆仓库
git clone https://github.com/creativebastard/rcommerce.git
cd gocart

# 启动所有服务
docker-compose up -d

# 检查状态
docker-compose ps

配置

选项 1:使用设置向导(推荐)

运行交互式设置向导:

# 运行设置向导
./target/release/rcommerce setup

# 或保存到特定路径
./target/release/rcommerce setup -o /etc/rcommerce/config.toml

向导将引导您完成: 1. 店铺信息(名称、默认货币) 2. 数据库连接 3. 数据库设置(迁移、导入) 4. 服务器配置 5. 缓存设置 6. 安全设置 7. 媒体存储 8. TLS/SSL 证书 9. 支付网关 10. 通知(电子邮件)

选项 2:手动配置

创建 config/development.toml 文件:

[server]
host = "127.0.0.1"
port = 8080
log_level = "debug"

[database]
type = "postgres"
host = "localhost"
port = 5432
username = "rcommerce_dev"
password = "devpass"
database = "rcommerce_dev"
pool_size = 5

[cache]
provider = "memory"  # 开发环境使用内存缓存

[payments]
default_gateway = "mock"

[logging]
level = "debug"
format = "text"

[features]
development_mode = true
debug_api = true

2. 设置数据库

PostgreSQL:

# 创建数据库
psql -U postgres -c "CREATE DATABASE rcommerce_dev;"
psql -U postgres -c "CREATE USER rcommerce_dev WITH PASSWORD 'devpass';"
psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE rcommerce_dev TO rcommerce_dev;"

3. 运行迁移

# 运行数据库迁移
cargo run -- migrate run

运行服务器

开发模式

# 使用热重载运行
cargo watch -x run

# 或直接运行
cargo run

# 使用特定配置
cargo run -- --config config/development.toml

生产模式

# 构建发布二进制文件
cargo build --release

# 使用生产配置运行
./target/release/rcommerce --config config/production.toml

验证安装

健康检查

curl http://localhost:8080/health

预期响应:

{
  "status": "healthy",
  "version": "0.1.0",
  "database": "connected",
  "cache": "connected",
  "timestamp": "2024-01-23T14:13:35Z"
}

创建您的第一个产品

curl -X POST http://localhost:8080/api/v1/products \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "name": "Test Product",
    "slug": "test-product",
    "description": "A test product",
    "price": 29.99,
    "status": "active"
  }'

下一步

故障排除

端口已被占用

# 查找使用端口 8080 的进程
lsof -i :8080

# 终止进程或使用不同端口
# 编辑 config/development.toml 并更改端口

数据库连接失败

# 检查 PostgreSQL 是否正在运行
pg_isready -h localhost -p 5432

# 检查凭据
psql -U rcommerce_dev -d rcommerce_dev -h localhost -W

构建错误

# 更新 Rust
rustup update

# 清理并重新构建
cargo clean
cargo build --release

获取帮助

  • 文档:浏览完整文档
  • GitHub Issues:报告错误和请求功能
  • Discord:加入社区获取实时帮助