A custom API for allowing users to upload and manage custom join sounds for Discord servers.
.
├── cmd/api/ # Application entrypoint
├── internal/
│ ├── database/ # Database layer
│ ├── handlers/ # HTTP handlers
│ ├── middleware/ # HTTP middlewares (including Auth0)
│ ├── models/ # Data models
│ └── utils/ # Utility functions
├── data/ # Database and file storage
This API uses Auth0 for authentication and authorization:
- JWT tokens are required for protected endpoints
- The JWT subject field contains Discord user ID for authorization
- Public endpoints (like file retrieval) don't require authentication
- Protected endpoints validate user ownership of resources
GET /api/v1/pingGET /api/v1/sound/:soundIdGET /api/v1/sounds/:guildId/:userIdGET /api/v1/settings/:guildId/:userIdPOST /api/v1/sounds/:guildId/:userId
Content-Type: multipart/form-data
Authorization: Bearer <jwt-token>
Parameters:
- files: Audio files to upload (max 5 files, max 10MB each)DELETE /api/v1/sound/:soundId
Authorization: Bearer <jwt-token>PATCH /api/v1/settings/:guildId/:userId
Content-Type: application/json
Authorization: Bearer <jwt-token>
Body:
{
"active_sound_id": "sound-id-here",
"mode": "enabled/disabled"
}- Maximum file size: 10MB per file
- Maximum files per user: 5 files
- Maximum audio duration: 5 seconds
- Supported formats: MP3 (.mp3), WAV (.wav)
- Maximum payload size: 50MB
- Go 1.25+
- SQLite3
- Auth0 account and application setup
The following environment variables are required:
AUTH0_DOMAIN: Your Auth0 domain (e.g.,your-domain.auth0.com)AUTH0_AUDIENCE: Your Auth0 API audience identifier
PORT: Server port (default:8081)DB_PATH: SQLite database path (default:./data/main.db)SOUNDS_PATH: Directory for storing sound files (default:./data/sounds)GIN_MODE: Gin framework mode (debug,release, default:debug)
- Set up your Auth0 application and get your domain and audience
- Create a
.envfile with your Auth0 credentials:
AUTH0_DOMAIN=your-domain.auth0.com
AUTH0_AUDIENCE=your-api-audience- Install dependencies and run:
# Install dependencies
go mod tidy
# Run the application
go run cmd/api/main.goTo ensure code quality, you can run linting and testing commands:
# Run linting
make lint
# Run format
make fmt
# Run tests
go test ./...# Make sure your .env file is in the project root
# Build and run with docker-compose
docker-compose up --build -dThe API will be available at http://localhost:8081