This project is the back-end service for a WeChat mini-program called "GoJxust", designed to provide campus services for Jiangxi University of Science and Technology (JXUST). The application is written in Go and utilizes the Gin web framework. It offers features such-as course selection assistance, course schedules, viewing exam failure rates, and more. The project follows a standard layered architecture, separating concerns into handlers, services, and models.
Key Technologies:
- Language: Go
- Web Framework: Gin
- Database: MySQL
- ORM: GORM
- Cache: Redis
- Authentication: JWT
- Configuration: Environment variables
- Object Storage: MinIO
- All handlers and services MUST pass the
ctx context.Contextparameter. - Use
helper.SuccessResponse(c, struct_or_msg)to return successful responses,helper.ErrorResponse(c, code, msg)to return error responses,helper.PageSuccessResponse(c, result, total, page, pageSize)for paginated responses. - All constants, except for those related to DTOs, are stored in
pkg/constant.
The project uses a Makefile to streamline common development tasks.
Build the application:
make build-apiserverThis command builds a Linux binary and places it in the ./bin directory.
Run the application:
The README.md suggests running the application directly using go run:
go run cmd/apiserver/main.goRun unit tests:
make testRun E2E tests:
E2E tests are written in Python using httpx. Before running, ensure:
- The API server is running in non-release mode (to enable mock login endpoint)
- RBAC roles and permissions are initialized in the database
# Initialize RBAC data (first time only)
mysql -u your_username -p your_database < scripts/init_rbac.sql
# Install dependencies
pip install httpx
# Run E2E tests (server must be running on localhost:8080)
python scripts/e2e_test.py
# Or specify a custom base URL
python scripts/e2e_test.py --base-url http://localhost:8085The E2E test script (scripts/e2e_test.py) covers:
- Public endpoints: health check, reviews, config, heroes, notifications, categories
- Authenticated endpoints: user profile, reviews CRUD, course table, fail rate, points, contributions, countdowns, study tasks
- Admin endpoints: reviews management, notifications management, heroes management, config management
Supported test user types for mock login:
basic: Basic user with standard permissionsactive: Active user with additional permissionsverified: Verified useroperator: Operator with content management permissionsadmin: Administrator with full permissions
Build a Docker image:
make docker-build- Architecture: The project follows a layered architecture:
internal/handlers: Contains the HTTP handlers that receive requests and send responses.internal/services: Contains the business logic.internal/models: Defines the data structures and interacts with the database.internal/router: Defines the API routes and wires up the handlers.internal/dto: Defines data transfer objects for requests and responses.internal/pkg/cache: Contains caching logic using Redis.internal/middleware: Contains middleware functions for authentication, logging, etc.internal/config: Manages application configuration via environment variables, loaded from a.envfile or yaml config file.pkg/constant: Contains application-wide constants.
- API Versioning: The API is versioned under the
/api/v0path. - Authentication: JWT-based authentication is used for protected routes. The authentication middleware is in
internal/middleware/middleware.go. - Database Migrations: The application uses GORM's auto-migration feature to keep the database schema up-to-date.
- Dependency Management: Go modules are used for dependency management. Dependencies are listed in the
go.modfile.