package remote import ( "git.sxidc.com/go-framework/baize/convenient/binding" "git.sxidc.com/go-framework/baize/convenient/binding/request" "git.sxidc.com/go-framework/baize/framwork/domain/entity" ) // Simple 关联的Bind参数 // LI 为左边实体的Info类型 // RI 为右边实体的Info类型 type Simple[LI any, RI any] struct { // 左领域实体,注意是Entity类型 Left entity.Entity // 右领域实体,注意是Entity类型 Right entity.Entity // 左领域实体不是本地的 LeftRemote bool // 右领域实体不是本地的 RightRemote bool // 数据库Schema Schema string // 中间表表名 MiddleTableName string // URL领域相对路径,如/person,后面会自动补充,如/person/右领域path/update LeftDomainPath string // URL领域相对路径,如/identity,后面会自动补充,如/identity/左领域path/update RightDomainPath string // 更新左实体关联使用的请求参数 LeftUpdateJsonBody request.Params // 查询左实体关联使用的请求参数,注意是Query类型 LeftQueryQueryParams request.Query // 更新右实体关联使用的请求参数 RightUpdateJsonBody request.Params // 查询右实体关联使用的请求参数,注意是Query类型 RightQueryQueryParams request.Query // 可选配置项,通过WithXXX配置 options *Options } func (simple *Simple[LI, RI]) bind(binder *binding.Binder) { //options := simple.options } func BindSimple[LI any, RI any](binder *binding.Binder, simple *Simple[LI, RI], opts ...Option) { options := new(Options) for _, opt := range opts { opt(options) } simple.options = options simple.bind(binder) } type Option func(options *Options) type Options struct { // 关闭左侧到右侧关联 disableLeft bool // 关闭右侧到左侧关联 disableRight bool // 关闭左侧更新 disableLeftUpdate bool // 关闭左侧查询 disableLeftQuery bool // 关闭右侧更新 disableRightUpdate bool // 关闭右侧查询 disableRightQuery bool } func WithDisableLeft() Option { return func(options *Options) { options.disableLeft = true } } func WithDisableRight() Option { return func(options *Options) { options.disableRight = true } } func WithDisableLeftUpdate() Option { return func(options *Options) { options.disableLeftUpdate = true } } func WithDisableLeftQuery() Option { return func(options *Options) { options.disableLeftQuery = true } } func WithDisableRightUpdate() Option { return func(options *Options) { options.disableRightUpdate = true } } func WithDisableRightQuery() Option { return func(options *Options) { options.disableRightQuery = true } }