35 lines
676 B
Go
35 lines
676 B
Go
package contracts
|
|
|
|
import (
|
|
"github.com/samber/do"
|
|
)
|
|
|
|
type Controller interface {
|
|
// 初始化
|
|
Init() error
|
|
// 获取 Container
|
|
Container() *do.Injector
|
|
// 派遣一个任务
|
|
Dispatch(job string, payload any, u User) error
|
|
}
|
|
|
|
type BaseController struct {
|
|
container *do.Injector
|
|
}
|
|
|
|
func (this BaseController) Container() *do.Injector {
|
|
return this.container
|
|
}
|
|
|
|
func (BaseController) Init() error {
|
|
return nil
|
|
}
|
|
|
|
func (this BaseController) Dispatch(job string, payload any, u User) error {
|
|
return do.MustInvoke[JobService](this.Container()).Dispatch(job, payload, u)
|
|
}
|
|
|
|
func NewBaseController(container *do.Injector) Controller {
|
|
return &BaseController{container}
|
|
}
|