This is a Go-based backend application for a delivery service company. The app enables parcel creation, delivery tracking, motorbike parcel pickup, and management functionalities with proper authentication and security.
go-delivery-app/
|-- cmd/
| |-- server/ # Entry point for the application
| |-- main.go # Main server start file
|-- internal/
| |-- auth/ # Authentication logic (JWT)
| |-- jwt.go
| |-- handlers/ # API request handlers (Controllers)
| |-- parcel.go
| |-- motorbike.go
| |-- admin.go
| |-- models/ # Data models (DB Schema)
| |-- models.go
| |-- services/ # Business logic services
| |-- db/ # Database connection and migrations
| |-- database.go
| |-- middleware/ # Logging, security, and other middleware
| |-- logging.go
|-- config/ # Configuration files (optional)
|-- migrations/ # Database migration files (optional)
|-- test/ # Test files
|-- logs/ # Logs folder
|-- go.mod # Go modules file
|-- go.sum # Go modules file
- Parcel Management: Users (senders) can create and track parcels, and motorbikes can pick up and deliver parcels.
- User Roles:
- Sender: Create parcels, track parcel status.
- Motorbike: View available parcels, pick up and deliver parcels.
- Admin: View all parcels, users, and parcel statuses.
- Authentication: JWT-based authentication and role-based authorization.
- Database: PostgreSQL is used for storing parcels, users, and related data.
- Logging: All actions are logged, and middleware is used to log requests.
- Security: Secure coding practices, JWT, HTTPS (recommended), and input sanitization.
- Concurrency: Safe concurrent access to database and parcel statuses.
- Go 1.16+
- PostgreSQL
- Git
- Clone the repository:
git clone https://github.com/yourusername/go-delivery-app.git
cd go-delivery-app
- Set up the PostgreSQL database:
CREATE DATABASE delivery;
- Update the connection details in
internal/db/database.go
:
dsn := "host=localhost user=postgres password=yourpassword dbname=delivery port=5432 sslmode=disable"
- Install dependencies:
go mod tidy
- Run the migrations (if using migrations):
go run cmd/migrations.go
- Start the server:
go run cmd/server/main.go
Server will run at localhost:8080
.
- Create Parcel:
POST /sender/parcel
- Get Parcel Status:
GET /sender/parcel/{id}
- List Available Parcels:
GET /motorbike/parcels
- Pick Parcel:
POST /motorbike/parcel/{id}/pickup
- View All Parcels:
GET /admin/parcels
- View All Users:
GET /admin/users
The app uses JWT for secure authentication. Each request should include the Authorization: Bearer <token>
header.
To run tests:
go test ./...
Logs are stored in the logs/
directory. Make sure to configure proper logging for production use.
- Use HTTPS for production.
- Implement proper rate limiting to prevent abuse.
- Regularly rotate JWT secret keys and other sensitive credentials.
- Securely hash and store passwords using
bcrypt
or similar libraries.
Feel free to submit pull requests or report issues on the GitHub repository.
MIT License. See LICENSE
for details.