Chirpy-Go is a Twitter-esque backend application built with Golang, PostgreSQL, and JWT authentication. This project implements secure login, advanced routing, middleware integration, and a refresh token system for seamless authentication flow. Additionally, it features an extended subscription model through the Chirpy-Red module, powered by Polka Key.
- File Serving: Serve static files efficiently using
http.StripPrefixandhttp.FileServer. - Health Checks: Readiness endpoints for monitoring application status.
- User Authentication: Secure login with JWT (JSON Web Tokens) and refresh token system for enhanced authentication.
- Database Management: PostgreSQL for efficient and reliable data handling.
- Advanced Routing and Middleware: Designed for scalable and maintainable APIs using native Golang
net/http. - Subscription Model: Integrated with Chirpy-Red, enabling subscriptions using Polka Key.
- Admin Metrics: Access metrics to monitor server performance.
- Golang 1.19 or later
- PostgreSQL 15 or later
$ git clone https://github.com/hawkaii/Chirpy-go.git
$ cd Chirpy-goCreate a .env file in the root directory with the following variables:
JWT_SECRET=dummy_jwt_secret_key
POLKA_SECRET=dummy_polka_secret_key
DB_URL="postgres://fake_user:fake_password@fake_host:5432/fake_database?sslmode=disable"$ go mod tidyEnsure PostgreSQL is running, and then use sqlc and goose to handle migrations:
- Generate SQL code for queries using
sqlc:
$ sqlc generate- Apply migrations using
goose:
$ goose -dir ./migrations postgres "postgres://fake_user:fake_password@fake_host:5432/fake_database?sslmode=disable" upRun the backend server:
$ go run main.goThe application will be accessible at http://localhost:8080.
- GET
/app/*- Serve static files from thefilepathRootdirectory.
- GET
/api/healthz- Check server readiness. - GET
/api/reset- Reset server state (for testing purposes).
- POST
/api/chirps- Create a new chirp. - GET
/api/chirps- Fetch all chirps. - GET
/api/chirps/{chirpID}- Retrieve a chirp by ID. - DELETE
/api/chirps/{chirpID}- Delete a chirp by ID.
- POST
/api/users- Create a new user. - PUT
/api/users- Update user information.
- POST
/api/login- Authenticate a user and return access and refresh tokens. - POST
/api/refresh- Generate a new access token using a valid refresh token. - POST
/api/revoke- Revoke tokens for logout.
- POST
/api/polka/webhooks- Handle subscription-related webhooks.
- GET
/admin/metrics- Retrieve server performance metrics.
- Language: Golang
- Database: PostgreSQL
- Authentication: JWT
- Routing: Native Golang
net/http - Middleware: Custom-built using native Golang
- Subscription Model: Polka Key integration
- Migrations:
sqlcandgoose
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature-name). - Commit your changes (
git commit -m 'Add a new feature'). - Push to the branch (
git push origin feature-name). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or suggestions, please reach out:
- GitHub: hawkaii
- Email: your_email@example.com
Enjoy using Chirpy-Go! 🚀