GitHub - nedssoft/go-basic-api: A basic API built with Go, Gin, and GORM
This project is a RESTful API built with Go, using Gin as the web framework and GORM for database operations.
Features
- User management (create, read)
- Post management (create, read)
- Database migrations
- End-to-end testing
Prerequisites
- Go 1.16+
- PostgreSQL
Setup
-
Clone the repository:
git clone https://github.com/nedssoft/go-basic-api.git cd go-basic-api -
Install dependencies:
-
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:
Running the Application
To start the server:
The server will run on port 8080 by default.
Testing
To run the tests:
This will run the tests for both the user and post endpoints.
API 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
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.