Integrate Qiniu upload service and update configuration
- Added Qiniu configuration options to .env.example and config.go for file uploads. - Refactored main.go to include new Qiniu service and upload handler. - Updated route registration to accommodate the new upload handler. - Enhanced documentation to include references for Qiniu upload functionality. - Removed legacy authentication handler and services to streamline the codebase.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"wx_service/internal/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MiniProgramService struct {
|
||||
// service 层负责“业务能力”,通常会依赖数据库/第三方客户端等基础设施。
|
||||
// 这里通过结构体字段持有 db(依赖注入),而不是在方法里自己创建连接。
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewMiniProgramService(db *gorm.DB) *MiniProgramService {
|
||||
return &MiniProgramService{db: db}
|
||||
}
|
||||
|
||||
func (s *MiniProgramService) GetByID(ctx context.Context, id uint) (*model.MiniProgram, error) {
|
||||
// WithContext(ctx) 能把请求的超时/取消信号传递给数据库层,避免慢请求一直挂着。
|
||||
var mp model.MiniProgram
|
||||
if err := s.db.WithContext(ctx).Where("id = ?", id).First(&mp).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &mp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user