This is a simple CRUD (Create, Read, Update, Delete) application written in Go, showcasing different routers and frameworks. The application allows you to perform operation on user data using various web frameworks and routers, including Chi, Echo, Gin, HttpRouter, Mux, and the standard net/http package.
The project follows the standard Go project layout and naming conventions, providing a clean and modular structure:
cmd/
: Contains the main application entry point (main.go
). This is where the main application logic resides.internals/
: Contains internal packages and modules that are specific to this application. These packages are not intended to be imported by external packages.config/
: Handles application configuration, such as database configuration (db.go
).db/
: Contains database related packages.migrate/
: Contains scriptmain.go
for database migration using golang-migrate.routers/
: Contains router implementations (chi_router.go
,echo_router.go
, etc.).handlers/
: Contains handler functions for each CRUD operation (chi_handler.go
,echo_handler.go
, etc.).sql/
: Containsschema.sql
andquery.sql
files for generating type safe GO code from the compiled sql using sqlc.
sqlc.yaml
: This is the configuration file used for working with sqlc.
Ensure you have the following installed on your machine:
- Go
- PostgreSQL Database
-
Go: The application is developed in Go. Install the latest version from the official website.
-
PostgreSQL Database: The application uses PostgreSQL as the database. Ensure it is installed and running.
Create a .env
file in the root of the project with the following content:
DATABASE_URL="postgresql://DB_USER:DB_PASSWORD@DB_HOST:DB_PORT/DB_NAME"
To initialize the database schema, run the migration script:
go run internals/migrate/main.go
To initialize the database schema, run the migration script:
go run cmd/main.go
Running at: http://localhost:8000
- Get All Users:
GET /users
- Create User:
POST /users
- Get User:
GET /users/:id
- Update User:
PUT /users/:id
- Delete User:
DELETE /users/:id
Running at: http://localhost:8001
- Get All Users:
GET /users
- Create User:
POST /users
- Get User:
GET /users/:id
- Update User:
PUT /users/:id
- Delete User:
DELETE /users/:id
Running at: http://localhost:8002
- Get All Users:
GET /users
- Create User:
POST /users
- Get User:
GET /users/:id
- Update User:
PUT /users/:id
- Delete User:
DELETE /users/:id
Running at: http://localhost:8003
- Get All Users:
GET /users
- Create User:
POST /users
- Get User:
GET /users/:id
- Update User:
PUT /users/:id
- Delete User:
DELETE /users/:id
Running at: http://localhost:8004
- Get All Users:
GET /users
- Create User:
POST /users
- Get User:
GET /users/:id
- Update User:
PUT /users/:id
- Delete User:
DELETE /users/:id
Running at: http://localhost:8005
- Get All Users:
GET /users
- Create User:
POST /users
- Get User:
GET /users/:id
- Update User:
PUT /users/:id
- Delete User:
DELETE /users/:id