Project Configuration Document
1. Project Overview
1.1 Project Structure
This project adopts a microservices architecture and is divided into two parts: the management system and the API system:
- Management System: Provides backend management functions, including system configuration, user management, data monitoring, permission control, etc.
- API System: Provides external interface services, handles client requests, and implements business logic.
1.2 Technology Stack
- Backend Language: Go language
- Web Framework: go-zero open-source framework
- Database: MySQL
- Cache: Redis
- File Storage: Object storage supporting S3 protocol
- Authentication: JWT (JSON Web Token)
- Permission Control: Casbin
2. Core Configuration Items
2.1 Basic Service Configuration
yaml
# Basic service information
Name: upgradelink-admin # Service name, used to identify different service instances
Host: 0.0.0.0 # Service listening address, 0.0.0.0 means listening on all network interfaces
Port: 9110 # Service listening port
# Service performance configuration
Timeout: 300000 # Request timeout (milliseconds)
MaxBytes: 1073741824 # Maximum request body size (bytes), 1GB here2.2 Runtime Environment Configuration
yaml
Mode: dev # Runtime mode: dev (development), test (testing), prod (production)
EnvMode: dev # Environment mode, similar to Mode, used to distinguish configurations for different environments2.3 File Storage Configuration
File storage supports S3 protocol object storage services. After configuration, you can test uploading files in the backend system (Cloud File Management -> Upload).
yaml
UploadConf:
Bucket: # Storage bucket name
SecretID: # Storage bucket access key ID
SecretKey: # Storage bucket access key
Endpoint: # Storage bucket endpoint
Folder: # Storage bucket folder
Region: # Storage bucket region
CdnUrl: # CDN domain name, will replace object storage URL prefix after configurationNote: After configuring
CdnUrl, the system will automatically replace the object storage URL prefix with the CDN domain name and store the replaced URL in the database, thus using CDN to accelerate file access.
2.4 Authentication Configuration
yaml
Auth:
AccessSecret: jS6VKDtsJf3z1n2VKDtsJf3z # JWT access secret, used to sign and verify tokens
AccessExpire: 259200 # JWT token expiration time (seconds), 3 days here2.5 CORS Configuration
yaml
CROSConf:
Address: '*' # Allowed cross-domain sources, * means allowing all sources2.6 Log Configuration
yaml
Log:
ServiceName: UpgradeLink-admin # Log service name
Mode: file # Log output mode: console or file
Encoding: json # Log encoding format: json or console
TimeFormat: "2006-01-02 15:04:05.000" # Log time format
Path: "./logs" # Log file storage path
Level: debug # Log level: debug, info, warn, error
KeepDays: 3 # Log file retention days
Rotation: daily # Log rotation method: daily or size2.7 Permission Control Configuration
Using Casbin to implement RBAC (Role-Based Access Control) permission management:
yaml
CasbinConf:
ModelText: |
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act
[role_definition]
g = _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = r.sub == p.sub && keyMatch2(r.obj,p.obj) && r.act == p.act2.8 Database Configuration
yaml
DatabaseConf:
Type: mysql # Database type
Host: 127.0.0.1 # Database host address
Port: 3306 # Database port
DBName: upgrade # Database name
Username: root # Database username
Password: Rootroot123! # Database password
MaxOpenConn: 100 # Maximum number of open connections
SSLMode: disable # SSL mode: disable or require
CacheTime: 5 # Cache time (seconds)
MysqlConfig: "&loc=Asia%2FShanghai" # MySQL additional configuration, setting time zone to Shanghai here2.9 Redis Configuration
yaml
RedisConf:
Host: 127.0.0.1:6379 # Redis host address and port
Db: 0 # Redis database number
Pass: a123456 # Redis password3. Configuration Management Best Practices
3.1 Environment Separation
- Development Environment: Use local database and Redis, enable detailed logs
- Testing Environment: Use test database, simulate production environment configuration
- Production Environment: Use official database, disable debug logs, enhance security configuration
3.2 Security Considerations
- Sensitive information (such as passwords, keys) should not be hard-coded in configuration files, it is recommended to use environment variables or configuration center
- Production environment should use HTTPS protocol
- Regularly update keys and passwords
- Limit access scope of database and Redis
3.3 Performance Optimization
- Adjust
MaxOpenConnparameter according to service load - Set cache time reasonably to reduce database access
- Optimize log level, avoid using debug level in production environment
- Regularly clean up log files to avoid insufficient disk space
4. Configuration File Example
The complete configuration file example is as follows:
yaml
# Basic service configuration
Name: upgradelink-admin
Host: 0.0.0.0
Port: 9110
Timeout: 300000
MaxBytes: 1073741824
# Runtime environment configuration
Mode: dev
EnvMode: dev
# Authentication configuration
Auth:
AccessSecret: jS6VKDtsJf3z1n2VKDtsJf3z
AccessExpire: 259200
# CORS configuration
CROSConf:
Address: '*'
# Log configuration
Log:
ServiceName: UpgradeLink-admin
Mode: file
Encoding: json
TimeFormat: "2006-01-02 15:04:05.000"
Path: "./logs"
Level: debug
KeepDays: 3
Rotation: daily
# File storage configuration
UploadConf:
Bucket:
SecretID:
SecretKey:
Endpoint:
Folder:
Region:
CdnUrl:
# Permission control configuration
CasbinConf:
ModelText: |
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act
[role_definition]
g = _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = r.sub == p.sub && keyMatch2(r.obj,p.obj) && r.act == p.act
# Database configuration
DatabaseConf:
Type: mysql
Host: 127.0.0.1
Port: 3306
DBName: upgrade
Username: root
Password: Rootroot123!
MaxOpenConn: 100
SSLMode: disable
CacheTime: 5
MysqlConfig: "&loc=Asia%2FShanghai"
# Redis configuration
RedisConf:
Host: 127.0.0.1:6379
Db: 0
Pass: a123456