This project is a RESTful API built with Go, using Gin as the web framework and GORM for database operations.
- User management (create, read)
- Post management (create, read)
- Database migrations
- End-to-end testing
- Go 1.16+
- PostgreSQL
-
Clone the repository:
git clone https://github.com/nedssoft/go-basic-api.git cd go-basic-api -
Install dependencies:
go mod download -
Set up your environment variables in a
.envfile:DB_HOST=localhost DB_USER=your_username DB_PASSWORD=your_password DB_NAME=your_database_name DB_PORT=5432 PORT=8080 -
Run database migrations:
make migrate
To start the server:
make run
The server will run on port 8080 by default.
To run the tests:
make test
This will run the tests for both the user and post endpoints.
POST /api/v1/users: Create a new userGET /api/v1/users/:id: Get a user by IDPOST /api/v1/posts: Create a new postGET /api/v1/posts: Get all postsGET /api/v1/posts/:id: Get a post by ID
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.