As a Java developer, I felt like I was stuck in a time machine. Then I heard about this hip new language called Go, and thought, "Hey, if it's good enough for the cool kids at Google, it's good enough for me!"
A simple backend server designed with hexagonal architecture to demonstrate how user authentication can be implemented.
- Allows new users to create an account and securely stores user data with hashed password in the MongoDB
- Verifies provided credentials against stored information in the database and authenticates users
- Generates a JSON Web Token (JWT) upon successful login
- Contains encoded user information and possibly authorization details
- Used for authenticating subsequent requests from the client
The application registers new users in a MongoDB database.
We can conveniently start an MongoDB instance in a Docker container. The corresponding Docker Compose file is already located in the root directory.
You can execute the compose.yml with the following command:
docker compose up -d
After starting the MongoDB container, the Go application can be launched using the following terminal command:
go run cmd/main.go
To register a new user, an HTTP POST request can be sent to the appropriate endpoint with a body containing the user credentials. Here's how you might do this:
curl -v -X POST http://localhost:8080/user/register \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"password": "test123"
}'
I welcome contributions from the community! Whether you're fixing bugs, improving documentation, or proposing new features, your efforts are appreciated.
This project is licensed under the MIT License - see the LICENSE file for details.