Clone the git repo - git clone git@github.com:golang-mitrah/gin-RestAPI-postgres-orm.git
- or download it.
This repository contains a simple REST API built using the Gin framework in Golang, with PostgreSQL as the database and an ORM for database interactions.
- Basic CRUD operations
- PostgreSQL database integration
- ORM for database operations
- Clean architecture and modular design
Before you begin, ensure you have met the following requirements:
- Go installed on your local machine
- PostgreSQL installed and running
- Git installed on your local machine
-
Clone the repository: git clone https://github.com/golang-mitrah/gin-RestAPI-postgres-orm.git
-
Navigate to the project directory: cd gin-RestAPI-postgres-orm
-
Install the dependencies: go mod tidy
-
Set up your PostgreSQL database and update the connection string in
database/database.go
.
Update the database connection string in `database/database.go`:
connection, err := gorm.Open(postgres.Open("host=localhost user=username dbname=gin_goorm_rest port=5432 password="), &gorm.Config{})
Adjust the host, user, dbname, port, and password according to your PostgreSQL setup.
- Run the application: To start the server, run: go run main.go The API will be available at http://localhost:8080.
The API provides the following endpoints:
Create a new user
- Endpoint:
POST /user
- Description: This endpoint is used to create a new user. It accepts a JSON payload with the user details and stores the user in the PostgreSQL database.
Get all users
- Endpoint:
GET /user
- Description: This endpoint retrieves all users from the database.
Get a specific user
- Endpoint:
GET /user/:id
- Description: This endpoint retrieves a specific user by their ID.
Update a user
- Endpoint:
PUT /user/:id
- Description: This endpoint updates the details of a specific user by their ID.
Delete a user
- Endpoint:
DELETE /user/:id
- Description: This endpoint deletes a specific user by their ID.
Gin GoORM REST api is authored by GoLang Mitrah and everyone is welcome to contribute.
If you experience any problems with Gin GoORM REST api API wrapper please:
- submit a ticket to our issue tracker
- fix the error yourself and send us a pull request