contracts/controller.go
2024-05-09 13:15:24 +08:00

36 lines
708 B
Go

package contracts
import (
"git.fsdpf.net/go/req"
"github.com/samber/do"
)
type Controller interface {
// 初始化
Init() error
// 获取 Container
Container() *do.Injector
// 派遣一个任务
Dispatch(job string, payload any, u req.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 req.User) error {
return do.MustInvoke[JobService](this.Container()).Dispatch(job, payload, u)
}
func NewBaseController(container *do.Injector) Controller {
return &BaseController{container}
}