85 lines
1.8 KiB
Go
85 lines
1.8 KiB
Go
package factory
|
|
|
|
import (
|
|
"git.toowon.com/jimmy/go-common/captcha"
|
|
"git.toowon.com/jimmy/go-common/email"
|
|
"git.toowon.com/jimmy/go-common/i18n"
|
|
"git.toowon.com/jimmy/go-common/logger"
|
|
"git.toowon.com/jimmy/go-common/mcp"
|
|
"git.toowon.com/jimmy/go-common/middleware"
|
|
"git.toowon.com/jimmy/go-common/sms"
|
|
"git.toowon.com/jimmy/go-common/storage"
|
|
"github.com/redis/go-redis/v9"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// WithStorage 注入自定义存储实现
|
|
func WithStorage(s storage.Storage) Option {
|
|
return func(f *Factory) {
|
|
f.storage = s
|
|
}
|
|
}
|
|
|
|
// WithLogger 注入自定义日志对象
|
|
func WithLogger(l *logger.Logger) Option {
|
|
return func(f *Factory) {
|
|
f.logger = l
|
|
}
|
|
}
|
|
|
|
// WithDatabase 注入自定义数据库连接
|
|
func WithDatabase(db *gorm.DB) Option {
|
|
return func(f *Factory) {
|
|
f.db = db
|
|
}
|
|
}
|
|
|
|
// WithRedis 注入自定义 Redis 客户端
|
|
func WithRedis(c *redis.Client) Option {
|
|
return func(f *Factory) {
|
|
f.redis = c
|
|
}
|
|
}
|
|
|
|
// WithEmail 注入自定义邮件客户端
|
|
func WithEmail(e *email.Email) Option {
|
|
return func(f *Factory) {
|
|
f.email = e
|
|
}
|
|
}
|
|
|
|
// WithSMS 注入自定义短信客户端
|
|
func WithSMS(s *sms.SMS) Option {
|
|
return func(f *Factory) {
|
|
f.sms = s
|
|
}
|
|
}
|
|
|
|
// WithI18n 注入自定义国际化对象
|
|
func WithI18n(i *i18n.I18n) Option {
|
|
return func(f *Factory) {
|
|
f.i18n = i
|
|
}
|
|
}
|
|
|
|
// WithMiddlewareChain 注入自定义中间件链
|
|
func WithMiddlewareChain(c *middleware.Chain) Option {
|
|
return func(f *Factory) {
|
|
f.chain = c
|
|
}
|
|
}
|
|
|
|
// WithMCP 注入自定义 MCP 管理器(如测试用的 fake 实现)
|
|
func WithMCP(m mcp.Manager) Option {
|
|
return func(f *Factory) {
|
|
f.mcp = m
|
|
}
|
|
}
|
|
|
|
// WithCaptcha 注入自定义图形验证码实现(如测试用的 fake 实现)
|
|
func WithCaptcha(c captcha.Manager) Option {
|
|
return func(f *Factory) {
|
|
f.captcha = c
|
|
}
|
|
}
|