- feat(config): TOML config with env overrides, strict parsing and validation - feat(storage): SQLite (modernc) and PostgreSQL (pgx) backends through bun, embedded per-driver SQL migrations with a transactional runner - feat(schema): catalog tables (artists, albums, tracks, audio_files with per-root paths), users and listening events with idempotency keys - feat(auth): Argon2id password hashing, HS256 JWT tokens, first-user-only registration and login - feat(api): gin REST API under /api/v1 (health, register, login, listens) with a consistent error envelope, body limit and request logging - feat(sondad): zap logger, graceful shutdown, composition root in main - chore: example config, .gitignore for secrets, DB files, IDE and agent files
18 lines
523 B
Go
18 lines
523 B
Go
package httpapi
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
// errorBody is the consistent error envelope: {"error":{"code":"...","message":"..."}}.
|
|
type errorBody struct {
|
|
Error errorDetail `json:"error"`
|
|
}
|
|
|
|
type errorDetail struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// writeError aborts the request with the standard error envelope.
|
|
func writeError(c *gin.Context, status int, code, message string) {
|
|
c.AbortWithStatusJSON(status, errorBody{Error: errorDetail{Code: code, Message: message}})
|
|
}
|