调整项目架构,让框架更优化
This commit is contained in:
68
factory/options.go
Normal file
68
factory/options.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package factory
|
||||
|
||||
import (
|
||||
"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/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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user