This is a Go-based web server application that provides various API endpoints and serves static files.
- File serving
- User authentication (login, refresh, revoke)
- User management (create, update)
- Chirp functionality (create, retrieve, delete)
- Webhook handling for Polka integration
- Health check endpoint
- Metrics tracking
- Ensure you have Go installed on your system.
- Clone this repository.
- Create a
.env
file in the root directory with the following variables. - Run
go mod tidy
to ensure all dependencies are installed.
To start the server, run:
go run main.go
The server will start on port 8080 by default.
To run in debug mode (which resets the database):
GET /api/healthz
: Health checkGET /api/reset
: Reset endpointPOST /api/polka/webhooks
: Webhook handler for PolkaPOST /api/revoke
: Revoke authenticationPOST /api/refresh
: Refresh authenticationPOST /api/login
: User loginPOST /api/users
: Create userPUT /api/users
: Update userDELETE /api/chirps/{chirpID}
: Delete a chirpPOST /api/chirps
: Create a chirpGET /api/chirps
: Retrieve chirpsGET /api/chirps/{chirpID}
: Get a specific chirpGET /admin/metrics
: View server metrics
Static files are served from the /app
route. The server looks for files in the current directory.
The application uses a JSON file (database.json
) as its database.
- github.com/joho/godotenv: For loading environment variables
- boot.dev-webserver/internal/database: Custom package for database operations
Ensure that the JWT_SECRET
and POLKA_KEY
environment variables are set before running the server.