This is a simple Go application designed for testing and showcasing basic skills in handling HTTP requests and working with a PostgreSQL database using the Go database/sql
package. The application provides basic CRUD operations for managing user records in a PostgreSQL database.
- Get All Users: Retrieve a list of all users from the database.
- Get User by ID: Retrieve details of a specific user based on their ID.
- Update User: Update the details of a user using their ID.
- Delete User: Delete a user from the database based on their ID.
Before running the application, make sure you have the following installed:
- Go (1.16 or later)
- PostgreSQL
go-chi
router:go get -u github.com/go-chi/chi/v5
-
Clone the repository:
git clone https://github.com/darlio/go-orm cd go-orm
-
Create a PostgreSQL database and set the connection details in a
.env
file:DB_URL=your_postgres_connection_url
-
Install dependencies:
go mod tidy
-
Run the application:
go run main.go
- Access the home route:
http://localhost:5000/
- Get all users:
http://localhost:5000/users
- Get a specific user:
http://localhost:5000/users/{id}
- Update a user: Send a PATCH request to
http://localhost:5000/users/{id}
with the updated user data. - Delete a user: Send a DELETE request to
http://localhost:5000/users/{id}
.
- chi - A lightweight, idiomatic and composable router for building Go HTTP services.