Ecommerce backbone API - using Go
- Gin is a web framework written in Go (Golang) that provides a set of features like routing, middleware, and binding for web applications.
- install:
go get -u github.com/gin-gonic/gin
- Zap is a high-performance, structured logging library for Go, designed and developed by Uber. It is one of the fastest logging libraries available, offering both structured (key-value) and unstructured (printf-style) logging.
- install:
go get -u go.uber.org/zap
- Viper is a popular configuration management library for Go, designed to handle dynamic configuration in Go applications. It simplifies working with different types of configuration formats and provides a consistent API to retrieve configuration values.
- install:
go get github.com/spf13/viper
- Lumberjack is a log rotation and compression package for Go, designed to be easy to use and integrate with other libraries and frameworks. It provides a simple and configurable way to rotate, compress, and store log files.
- install:
go get github.com/natefinch/lumberjack
go get github.com/natefinch/lumberjack
- Note: This package is used for logging.
- JWT-Go is a Go package for implementing JWT (JSON Web Tokens) as per RFC 7519. It provides a simple and efficient way to handle JSON Web Tokens in Go applications.
- install:
go get -u github.com/dgrijalva/jwt-go
- Note: This package is used for JWT authentication.
go get -u github.com/go-sql-driver/mysql
- Redis is an open-source, in-memory data structure store, used as a database, cache, and message broker.
- install:
go get github.com/go-redis/redis/v8
go get github.com/segmentio/kafka-go
- GORM is an open-source ORM (Object-Relational Mapping) library for Go, providing a simple and efficient way to interact with a relational database.
- install:
go get -u gorm.io/gorm
go get -u gorm.io/driver/mysql
- Google UUID is a package for generating and parsing UUIDs in Go. It provides a simple and efficient way to generate and validate UUIDs.
- install:
go get -u github.com/google/uuid
- Benchmark is a testing tool in Go that provides a way to measure the performance of code. It is useful for testing the performance of functions, methods, and entire packages.
- install:
go get -u golang.org/x/perf/cmd/benchcmp
- Run tests with coverage:
go test -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
go test ./test/redis/ -v
go test ./test/basic/ -v
go test ./test/<other>/ -v
curl -H "Authorization: valid-token" curl http://localhost:8080/user/email/phuc@gmail.com
curl http://localhost:8080/user/email/phuc@gmail.com
mysql -h 127.0.0.1 -P 3306 -u root -p --protocol=tcp
GRANT ALL PRIVILEGES ON *.* TO 'phuc'@'%' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
docker exec -it mysql-db bash
mysql -uroot -p123456
use boxfetch;
show tables;
desc go_db_user;
go test -bench=. -benchmem
docker-compose down --volumes
docker system prune -f --volumes
mkdir -p ./redis_data
docker-compose up -d
docker network ps
docker network inspect docker network inspect nginx-mysql-network
sudo lsof -i :8080
Here are the updated curl
commands with the port changed to 8999
:
curl -X POST http://localhost:8999/v1/2024/user/register
-H "Content-Type: application/json"
-d '{"username": "newuser", "password": "password123", "email": "newuser@example.com"}'
curl -X POST http://localhost:8999/v1/2024/user/send_otp
-H "Content-Type: application/json"
-d '{"phone": "+1234567890"}'
curl -X GET http://localhost:8999/v1/2024/user/get_info
-H "Authorization: Bearer <your_token_here>"
curl -X POST http://localhost:8999/v1/2024/admin/login
-H "Content-Type: application/json"
-d '{"username": "admin", "password": "admin123"}'
curl -X POST http://localhost:8999/v1/2024/admin/active_user/123
-H "Authorization: Bearer <admin_token_here>"
curl -X POST http://localhost:8999/v1/2024/admin/add_shop
-H "Authorization: Bearer <admin_token_here>"
-H "Content-Type: application/json"
-d '{"shop_name": "New Shop", "owner": "owner_id"}'
curl -X PUT http://localhost:8999/v1/2024/admin/user/update/123
-H "Authorization: Bearer <admin_token_here>"
-H "Content-Type: application/json"
-d '{"email": "updatedemail@example.com", "status": "active"}'
curl -X POST http://localhost:8999/v1/2024/admin/user/deactivate/123
-H "Authorization: Bearer <admin_token_here>"
curl -X DELETE http://localhost:8999/v1/2024/admin/user/delete/123
-H "Authorization: Bearer <admin_token_here>"
curl -X POST http://localhost:8999/v1/2024/product/add
-H "Authorization: Bearer <admin_token_here>"
-H "Content-Type: application/json"
-d '{"product_name": "New Product", "price": 100}'
curl -X GET http://localhost:8999/v1/2024/product/list
-H "Authorization: Bearer <admin_token_here>"
curl -X GET http://localhost:8999/v1/2024/checkStatus
All curl
commands are now updated to use port 8999
. You can run these commands to test your API with the new port configuration.
Let me know if you need further modifications or assistance!