docs: 完善 README,移除未使用的 MinIO,修正 openapi 路径 (#48)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,2 +1,106 @@
|
||||
# goods
|
||||
商品档案公开API
|
||||
# OpenGoods
|
||||
|
||||
OpenGoods(天工·商品标签)提供公开、只读的商品事实 API,并配套运营后台和数据采集工具。项目整理商品名称、品牌、品类、条码、配料、营养成分、产地等客观信息,不提供购买或交易功能。
|
||||
|
||||
## 项目组成
|
||||
|
||||
- **公开 API**:Go 服务,提供商品搜索、品牌和商品详情等只读接口。
|
||||
- **运营后台**:独立的 Go 管理服务,提供登录、商品维护、投稿审核、API Key 和导入功能。
|
||||
- **数据采集**:`ingestion/` 是 Python 采集与 ETL 包;`tools/bypos-collector/` 包含 BYPOS 采集工具。
|
||||
- **前端**:`public-frontend/` 是公开站点,`admin-frontend/` 是运营后台界面;两者均使用 React、Vite 和 TypeScript。
|
||||
- **数据库迁移**:`migrations/` 保存 PostgreSQL schema 的正向与回滚迁移。
|
||||
|
||||
## API 与文档
|
||||
|
||||
- API 使用说明:[`docs/api.md`](docs/api.md)
|
||||
- OpenAPI 规范源文件:[`api/internal/handler/openapi.json`](api/internal/handler/openapi.json)
|
||||
- 数据契约:[`docs/data-contract.md`](docs/data-contract.md)
|
||||
- 采集说明:[`docs/etl-openfoodfacts.md`](docs/etl-openfoodfacts.md) 和 [`docs/ingestion-management.md`](docs/ingestion-management.md)
|
||||
- 部署指南:[`docs/deploy.md`](docs/deploy.md)
|
||||
|
||||
运行中的公开服务也通过 `GET /api/v1/openapi.json` 提供机器可读规范。
|
||||
|
||||
## 本地开发
|
||||
|
||||
需要 Go(版本要求见 `api/go.mod`)、Docker Compose、Node.js/npm,以及 Python 3.11 或更新版本(用于采集侧开发)。
|
||||
|
||||
启动 PostgreSQL 和 Redis:
|
||||
|
||||
```bash
|
||||
docker compose up -d postgres redis
|
||||
```
|
||||
|
||||
安装迁移工具并应用数据库迁移:
|
||||
|
||||
```bash
|
||||
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@v4.18.1
|
||||
migrate -path migrations \
|
||||
-database 'postgres://opengoods:opengoods@localhost:5432/opengoods?sslmode=disable' up
|
||||
```
|
||||
|
||||
启动公开 API:
|
||||
|
||||
```bash
|
||||
cd api
|
||||
export OPENGOODS_DATABASE_URL='postgres://opengoods:opengoods@localhost:5432/opengoods?sslmode=disable'
|
||||
export OPENGOODS_REDIS_URL='redis://localhost:6379/0'
|
||||
go run ./cmd/server
|
||||
```
|
||||
|
||||
在另一个终端启动运营后台(本地示例凭据请自行替换):
|
||||
|
||||
```bash
|
||||
cd api
|
||||
export OPENGOODS_DATABASE_URL='postgres://opengoods:opengoods@localhost:5432/opengoods?sslmode=disable'
|
||||
export OPENGOODS_REDIS_URL='redis://localhost:6379/0'
|
||||
export GOODS_ADMIN_ADDR=':8081'
|
||||
export GOODS_ADMIN_USER='admin'
|
||||
export GOODS_ADMIN_PASSWORD='local-development-password'
|
||||
export GOODS_ADMIN_JWT_SECRET='local-development-secret-change-before-use'
|
||||
go run ./cmd/admin
|
||||
```
|
||||
|
||||
前端可在各自目录启动 Vite 开发服务器(分别在两个终端运行):
|
||||
|
||||
```bash
|
||||
cd public-frontend
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
```bash
|
||||
cd admin-frontend
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## 测试与构建
|
||||
|
||||
Go API:
|
||||
|
||||
```bash
|
||||
cd api
|
||||
test -z "$(gofmt -l .)"
|
||||
go vet ./...
|
||||
go build ./...
|
||||
go test ./...
|
||||
```
|
||||
|
||||
Python 采集侧:
|
||||
|
||||
```bash
|
||||
cd ingestion
|
||||
pip install -e ".[dev]"
|
||||
ruff check .
|
||||
ruff format --check .
|
||||
pytest -q
|
||||
```
|
||||
|
||||
前端构建:
|
||||
|
||||
```bash
|
||||
(cd public-frontend && npm install && npm run build)
|
||||
(cd admin-frontend && npm install && npm run build)
|
||||
```
|
||||
|
||||
生产部署步骤、环境变量和反向代理配置见[部署文档](docs/deploy.md)。
|
||||
|
||||
Reference in New Issue
Block a user