mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-28 07:36:38 +08:00
1.5 KiB
1.5 KiB
go-backend
Admin API for FLVX. Go + net/http + GORM (SQLite/PostgreSQL).
Structure
| Dir | Role |
|---|---|
cmd/paneld/main.go |
Entry point, HTTP server + WebSocket |
internal/http/router.go |
Route registration (http.ServeMux) + middleware chain |
internal/http/handler/ |
API handlers |
internal/http/middleware/ |
JWT, CORS, logging, recover |
internal/http/response/ |
JSON envelope helpers |
internal/store/model/model.go |
All GORM models (single file) |
internal/store/repo/ |
Repository layer (never access DB directly) |
internal/auth/ |
Auth logic |
tests/contract/ |
Integration tests |
Conventions
- Auth: raw JWT in
Authorizationheader — noBearerprefix. - API envelope:
{code, msg, data, ts}, code 0 = success. - Repository pattern: handlers call repo methods, never
repo.DB()directly. - GORM:
TableName()on every model (GORM pluralizes by default). - GORM tags: no
type:jsonbortype:serial(SQLite incompatible). - SQLite:
MaxOpenConns(1), WAL mode,busy_timeout=5000. - Schema: created via
autoMigrateAll()at startup, no hand-written DDL. - PostgreSQL: set
DB_TYPE=postgresandDATABASE_URLenv vars. - Config: all from environment variables.
Commands
go run ./cmd/paneld # SERVER_ADDR defaults to :6365
make build
go test ./... # includes contract tests
go test ./tests/contract/... # contract tests only