GoBikes is a simple backend service designed for a bike rental application. The primary motivation behind this project is to explore backend engineering, understand its complexities, and apply key concepts like database management, API development, and performance optimization.
- Programming Language: Go (Golang)
- Web Framework: Gin - Fast HTTP framework for Go
- Database: MySQL
- ORM: GORM
- API Testing: Postman / Curl
- Tools: Docker (optional), Git
-
Vehicle Listing:
- Exposes an API to list all vehicles filtered by location.
- Sorts vehicles based on their base cost.
-
Cost Calculation:
- API to calculate the final cost based on selected start and end time.
- Applies rules like base pricing, hourly charges, and kilometer limits.
-
Booking Management:
- Place an order to rent a bike for a certain duration.
- Generates a unique order ID upon successful booking.
-
Data Relationships:
- Handles relationships between vehicles, locations, and costs using foreign keys.
-
JWT based authentication
Method | Endpoint | Description |
---|---|---|
GET |
/vehicle/{location_name} |
List all vehicles in the specified location. |
GET |
/vehicle/{location_name}/{vehicle_id}/{start_time}/{end_time} |
Retrieve the final rental cost. |
POST |
/order/vehicle |
Place an order for renting a vehicle. |
Endpoint: /order/vehicle
Method: POST
Request Body:
{
"vehicle_id": "1234",
"start_time": "1734420600",
"end_time": "1734442200"
}
Response:
{
"order_id": "ORD123456",
"message": "Booking successful"
}
Column | Type | Description |
---|---|---|
id | BIGINT | Primary Key |
model | TEXT | Vehicle model name |
year | BIGINT | Manufacture year |
type_id | BIGINT | Foreign key to vehicle_types |
available | BOOLEAN | Availability status |
booked_till_date | TEXT | Date until the vehicle is booked |
price_per_hour | FLOAT | Hourly rental price |
image | TEXT | Vehicle image URL |
Column | Type | Description |
---|---|---|
id | BIGINT | Primary Key |
vehicle_id | BIGINT | Foreign Key to vehicles.id |
base_cost | FLOAT | Base cost for initial duration |
hourly_cost | FLOAT | Cost per additional hour |
km_limit | INT | Kilometers allowed for the period |
Column | Type | Description |
---|---|---|
location_id | BIGINT | Primary Key |
name | TEXT | Location name |
This project has been a hands-on experience to understand:
- Structuring backend services in Go.
- Managing data relationships and performing JOIN queries with GORM.
- Building RESTful APIs using the Gin framework.
- Calculating dynamic costs with time-based pricing and constraints.
- Query optimization and API performance tuning.
- Install Go (1.19 or higher).
- MySQL Database.
- Git.
-
Clone the repository:
git clone https://github.com/hardikm9850/Go-Bikes.git cd gobikes
-
Set up MySQL Database:
- Import the provided
gobikesdb.sql
file.
- Import the provided
-
Update
config.json
(or.env
) with database credentials:{ "DB_USER": "root", "DB_PASS": "password", "DB_NAME": "gobikes", "DB_HOST": "localhost", "DB_PORT": "3306" }
-
Run the server:
go run main.go
-
Test APIs using Postman or Curl.
As this project is for learning purposes, contributions are welcome! Feel free to:
- Report issues.
- Suggest improvements.
- Share ideas for new features.
- Gin Web Framework for making API development smooth.
- GORM for simplifying database operations.
This project is licensed under the MIT License.
You’re free to use, modify, and distribute the code for learning purposes.
- Implement a payment gateway for order payments.
- Enhance cost calculation to include dynamic discounts and penalties.
- Containerize the app using Docker for easy deployment.
- Write unit tests to improve code quality.