A simple and clean RESTful API built with Golang (Gin), MongoDB, and JWT Authentication.
Now fully Dockerized for better development and deployment experience.
This API allows you to register, log in, and manage users securely.
- ✅ User registration and login with hashed passwords (bcrypt)
- ✅ JWT-based authentication middleware
- ✅ Full CRUD operations on users
- ✅ Input validation with
go-playground/validator - ✅ Swagger documentation (
swaggo/gin-swagger) - ✅ MongoDB integration using
mongo-driver - ✅ Docker + Docker Compose support
git clone https://github.com/NeginSal/go-crud-api.git
cd go-crud-api
PORT=8080
MONGO_URI=mongodb://mongo:27017
JWT_SECRET=your_super_secret_key
docker-compose up --build
Access the API at: http://localhost:8080
Swagger UI at: http://localhost:8080/swagger/index.html
git clone https://github.com/NeginSal/go-crud-api.git
cd go-crud-api go mod tidy
MONGODB_URI=
JWT_SECRET=your_jwt_secret
PORT=8080
go run main.go
Once the server is running, you can access Swagger UI at: http://localhost:8080/swagger/index.html
The API is documented using swaggo/swag. To regenerate docs after changes : swag init
- Register with /signup
- Log in with /login
- Use the returned token (JWT) in the Authorization header for protected routes: Authorization: Bearer
go-crud-api/
│
├── main.go
├── config/ ← Database settings and ...
│ └── db.go
├── controller/ ← Controllers (logic related to APIs)
│ └── user.go
├── model/ ← Data structures and models
│ └── user.go
├── middleware/ ← Middlewares (like auth)
│ └── authMiddleware.go
├── routes/ ← Routing
│ └── userRoutes.go
├── utils/ ← Helper functions (like ValidateToken)
│ └── jwt.go
├── go.mod / go.sum ← Package information
└── README.md ← Project description
You can learn more about this project in this link go-crud-api.
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.