This is a basic user CRUD (Create, Read, Update, Delete) API built in Go, designed to demonstrate clean architecture, layered structure, and proper use of Go with MongoDB and Swagger. The project is based on teachings from the HunCoding YouTube channel and can be freely used, modified, or studied by others.
β Inspired and guided by the amazing work of HunCoding
- Project Name: golang
- Version: 1.0
- Host: http://localhost:8080
- Repository: github.com/ale-neto/golang
Before getting started, ensure the following tools are installed:
git clone https://github.com/ale-neto/golang.git
cd golangdocker compose updocker container run --name golang-mongo -p 27017:27017 -d mongo
go run main.goThe app will be running at: http://localhost:8080
Once the application is running, you can test it using Swagger UI:
http://localhost:8080/swagger/index.html#
Or via tools like curl and Postman.
- Create user:
curl -X POST -H "Content-Type: application/json" \
-d '{"name":"Alexandre", "email":"alexandre@example.com", "age":30, "password":"Test@123"}' \
http://localhost:8080/user/create- Update user:
curl -X PUT -H "Content-Type: application/json" \
-d '{"name":"Alexandre Neto"}' \
http://localhost:8080/user/create/{id}- Delete user:
curl -X DELETE http://localhost:8080/user/delete/{id}email string // required, must be valid email
password string // required, min 6 chars, at least one special (!@#$%*)name string // required, 4β100 chars
email string // required, valid email
age int // required, between 1 and 140
password string // required, min 6 chars, at least one specialname string // required
age int // requiredid string
name string
email string
age intcode int
error string
message string
causes []struct {
field string
message string
}For protected endpoints, include the token in the
Authorizationheader:Bearer <your-access-token>
- Create a new user
- Body:
UserRequest - Response:
200 OK,400 Bad Request,500 Internal Server Error
- Delete user by ID
- Path param:
id - Response:
200 OK,400,500
- Get user by email
- Path param:
email - Response:
200 OK,404 Not Found,400 Invalid ID
- Get user by ID
- Path param:
id - Response:
200 OK,404 Not Found,400 Invalid ID
- Login with credentials
- Body:
UserLogin - Response:
200 OK (returns token),403 Forbidden
- Update user info by ID
- Path param:
id - Body:
UserUpdateRequest - Response:
200 OK,400,500
Feel free to fork the project, open issues or submit pull requests.
This project is heavily based on the work of HunCoding. Special thanks for all the knowledge shared freely on his YouTube channel. This repo exists thanks to that!
This project is open and free to use β no license restrictions apply.
Enjoy the code and happy coding with Go!