You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"joybuywork/internal/app"
|
|
"joybuywork/internal/plugins/jsonm"
|
|
"joybuywork/internal/repository/dao"
|
|
"joybuywork/internal/service/provider/fissionaction"
|
|
"joybuywork/internal/service/provider/operatelog"
|
|
"joybuywork/internal/service/provider/traces"
|
|
)
|
|
|
|
type CtxOption func(ctx *Context)
|
|
|
|
func WithDao(dao *dao.Query) CtxOption {
|
|
return func(ctx *Context) {
|
|
ctx.dao = dao
|
|
}
|
|
}
|
|
|
|
func WithFnTm(fnTm *traces.FnTimers) CtxOption {
|
|
return func(ctx *Context) {
|
|
ctx.fnTimer = fnTm
|
|
}
|
|
}
|
|
|
|
type Option func(logic *Logic)
|
|
|
|
// WithTran 使用事务的dao
|
|
func WithTran() Option {
|
|
return func(logic *Logic) {
|
|
logic.Tran()
|
|
}
|
|
}
|
|
|
|
// WithOnce 启用锁
|
|
func WithOnce(key string) Option {
|
|
return func(logic *Logic) {
|
|
logic.once = &once{
|
|
key: key,
|
|
lock: app.NewRedisLock(logic.Ctx, key),
|
|
}
|
|
}
|
|
}
|
|
|
|
// WithBp 启用埋点
|
|
func WithBp() Option {
|
|
return func(logic *Logic) {
|
|
logic.markPoint = fissionaction.NewMarkPoint(logic.Ctx, fissionaction.SetBatch())
|
|
}
|
|
}
|
|
|
|
func WithErrNotifyEqCode(code ...int32) Option {
|
|
return func(logic *Logic) {
|
|
logic.errNotify.eqCode = code
|
|
}
|
|
}
|
|
|
|
func WithErrNotifyNeqCode(code ...int32) Option {
|
|
return func(logic *Logic) {
|
|
logic.errNotify.neqCode = make(map[int32]struct{}, len(code))
|
|
for _, v := range code {
|
|
logic.errNotify.neqCode[v] = struct{}{}
|
|
}
|
|
}
|
|
}
|
|
|
|
func WithErrData(data any) Option {
|
|
return func(logic *Logic) {
|
|
logic.errData, _ = jsonm.Marshal(data)
|
|
}
|
|
}
|
|
|
|
// WithOl 启用操作记录
|
|
func WithOl() Option {
|
|
return func(logic *Logic) {
|
|
logic.ol = operatelog.NewOperateLog(logic.Ctx, operatelog.SetBatch())
|
|
}
|
|
}
|