A RESTful user management service built with Go, MongoDB, and Uber Fx for dependency injection.
- User registration and authentication
- Password hashing using bcrypt
- MongoDB for data persistence
- Dependency injection using Uber Fx
- RESTful API endpoints for CRUD operations
- Go 1.21 or higher
- MongoDB running on localhost:27017
- Clone the repository:
git clone <repository-url>
cd go-di-webservice
- Install dependencies:
go mod tidy
- Run the application:
go run main.go
The server will start on http://localhost:8080
.
POST /users
Content-Type: application/json
{
"email": "[email protected]",
"password": "password123",
"first_name": "John",
"last_name": "Doe"
}
GET /users/{id}
PUT /users/{id}
Content-Type: application/json
{
"first_name": "John",
"last_name": "Doe",
"password": "newpassword" // Optional
}
DELETE /users/{id}
POST /users/login
Content-Type: application/json
{
"email": "[email protected]",
"password": "password123"
}
.
├── internal/
│ ├── config/ # MongoDB configuration
│ ├── models/ # Data models
│ ├── repositories/# Data access layer
│ ├── services/ # Business logic
│ └── handlers/ # HTTP handlers
├── main.go # Application entry point
└── README.md
- Gorilla Mux - HTTP router
- MongoDB Go Driver - MongoDB driver
- Uber Fx - Dependency injection
- Crypto - Password hashing