- JWT-based authentication and authorization
- RESTful API with Gin framework
- Input validation using go-playground/validator
- MongoDB for database operations
Before you begin, ensure you have the following installed on your machine:
git clone https://github.com/Nhathuy1305/AdminGo.git
cd AdminGo
This project uses Go modules to manage dependencies. You can install the required dependencies using the following command:
go mod tidy
Change .env-example
to .env
file in the root directory and configure the following environment variables:
PORT=8000 #Optional
MONGO_INITDB_ROOT_USERNAME=
MONGO_INITDB_ROOT_PASSWORD=
MONGO_HOST=
MONGO_PORT=
Run the Docker Compose to start using the application:
docker-compose up -d
Create the Docker Images with these commands:
docker run -d --name mongo-demo \
-e MONGO_INITDB_ROOT_USERNAME=your-username \
-e MONGO_INITDB_ROOT_PASSWORD=your-password \
-p 27018:27017 \
mongo:6.0
- Remember to change
mongo-demo
,your-username
andyour-password
with your image, root username and password of your database.
Run the application by the following command:
go run main.go
The backend service will start on http://localhost:8000
.
To build the application, run the following command:
go build -o admingo
./admingo
- Access the MongoDB Image using this command:
docker exec -it mongo-demo /bin/bash
- Access the MongoDB shell:
mongosh -u your-username -p your-password
- List all databases:
show dbs
- Access a specific database:
use your_database_name
- List all collections (tables) in the database:
show collections
- Show data in a specific collection:
db.your_collection_name.find().pretty()
For example:
docker exec -it mongo-demo /bin/bash
mongosh -u mongotest -p 123456
show dbs
use restaurant
show collections
db.user.find().pretty()
GET /users
- Retrieve a list of users.GET /users/:user_id
- Retrieve a specific user by ID.POST /users/signup
- Register a new user.POST /users/login
- Authenticate a user and obtain a JWT token.
GET /foods
- Retrieve a list of food items.GET /foods/:food_id
- Retrieve a specific food item by ID.POST /foods
- Add a new food item.PATCH /foods/:food_id
- Update an existing food item.
GET /menus
- Retrieve a list of menus.GET /menus/:menu_id
- Retrieve a specific menu by ID.POST /menus
- Add a new menu.PATCH /menus/:menu_id
- Update an existing menu.
GET /tables
- Retrieve a list of tables.GET /tables/:table_id
- Retrieve a specific table by ID.POST /tables
- Add a new table.PATCH /tables/:table_id
- Update an existing table.
GET /orders
- Retrieve a list of orders.GET /orders/:order_id
- Retrieve a specific order by ID.POST /orders
- Place a new order.PATCH /orders/:order_id
- Update an existing order.
GET /orderItems
- Retrieve a list of order items.GET /orderItems/:orderItem_id
- Retrieve a specific order item by ID.GET /orderItems-order/:order_id
- Retrieve order items by order ID.POST /orderItems
- Add a new order item.PATCH /orderItems/:orderItem_id
- Update an existing order item.
GET /invoices
- Retrieve a list of invoices.GET /invoices/:invoice_id
- Retrieve a specific invoice by ID.POST /invoices
- Create a new invoice.PATCH /invoices/:invoice_id
- Update an existing invoice.
This project uses the following Go packages:
- github.com/dgrijalva/jwt-go v3.2.0+incompatible
- github.com/gin-gonic/gin v1.10.0
- github.com/go-playground/validator/v10 v10.20.0
- go.mongodb.org/mongo-driver v1.16.0
- golang.org/x/crypto v0.23.0
- LinkedIn: https://www.linkedin.com/in/nhathuy1305
- Email: [email protected]
This project is licensed under the MIT License. See the LICENSE file for more details.