Web Analytics

karpov-gateway

⭐ 153 stars English by MiChongs

Karpov Gateway

Integrated API Gateway + Console. Go backend (Gin + gRPC) + Next.js frontend (App Router + shadcn/ui), comes with credential pool, email verification, Linux.do OAuth2 SSO, quota billing, TOTP two-factor authentication.

License: MIT Go Next.js

✨ Features

🏗 Repository Structure

karpov-gateway/
├── gateway/             # Go 后端 (Gin + gRPC)
│   ├── cmd/             # 各 service 入口 (gateway/auth/music/pool/...)
│   ├── internal/        # 业务实现 (private)
│   ├── api/             # protobuf 定义
│   ├── migrations/      # PostgreSQL schema
│   ├── go.mod           # Go 模块 (go 1.24+)
│   └── Dockerfile
├── web/                 # Next.js 16 前端控制台
│   ├── src/             # App Router pages + components
│   ├── middleware.ts    # CSRF / session / CSP nonce
│   ├── package.json     # pnpm workspace
│   └── Dockerfile
├── deploy/
│   ├── compose/         # 本地开发 (PG + Redis + pgAdmin)
│   └── compose-prod/    # 生产单机 (gateway + web + PG + Redis 全栈)
└── .github/workflows/   # GitHub Actions CI (lint / test / build / govulncheck / gosec)

🚀 Quick Start

1. Prerequisites

| Tool | Version | | ---------- | ------- | | Go | 1.24+ | | Node.js | 20.11+ | | pnpm | 9+ | | Docker | 24+ | | PostgreSQL | 14+ | | Redis | 7+ |

2. Start Dependencies (Postgres + Redis + pgAdmin)

cd deploy/compose
cp .env.example .env       # 改强密码!
docker compose up -d

3. Starting the Gateway Backend

cd gateway
cp .env.example .env       # 与 deploy/compose/.env 的 PG/Redis 密码保持一致
go mod download
go run ./cmd/qqmusic-gateway

默认 :8080 (HTTP) + :9000 (gRPC)

首次启动会在 stderr 打印一个 superadmin 账号 + 临时密码

4. Start the Web Console

cd web
cp .env.example .env.local
pnpm install
pnpm dev

http://localhost:3000

🐳 Production Deployment (Docker Compose Standalone)

cd deploy/compose-prod
cp .env.example .env

编辑 .env:填入真域名 / 强密码 / SMTP 凭据 / OAuth client

nano .env

生成 KEK

openssl rand -hex 32 # → 写到 POOL_KEK_HEX=

docker compose up -d --build docker compose logs -f gateway

Notes:

🔐 OAuth2 (Linux.do) Integration

   OAUTH_LINUXDO_ENABLED=true
   OAUTH_LINUXDO_CLIENT_ID=...
   OAUTH_LINUXDO_CLIENT_SECRET=...
   OAUTH_LINUXDO_MIN_TRUST_LEVEL=1
   OAUTH_PUBLIC_BASE=https://your-domain
   OAUTH_FRONTEND_BASE=https://your-domain
   ``
  • Restart the gateway, and the login page / registration page will automatically display "Linux.do One-Click Login"

🧪 Test / Lint

bash

Go

cd gateway go vet ./... go test -race ./... golangci-lint run --timeout=5m

Web

cd web pnpm lint pnpm typecheck
`

📦 Key Dependencies

Backend

Frontend

📜 License

MIT — see LICENSE

🤝 Contributing

PR / Issue welcome. Before submitting PR, please:

🔒 Security

If you find security issues, please contact the maintainer directly, do not open a public issue.


Built with ❤️ by MiChongs

--- Tranlated By Open Ai Tx | Last indexed: 2026-06-04 ---