GAAS GFrame项目web后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

  1. // Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
  2. package container
  3. import (
  4. "errors"
  5. "fmt"
  6. )
  7. // 新事务代理创建器
  8. // @Implement LAPP_GAAS_GFrame_BACKEND/container/CallerBrokerBuilder
  9. type NewTransactionBrokerBuilder struct {
  10. }
  11. // 创建新事务代理创建器
  12. // 返回值:
  13. // 1.新事务代理创建器
  14. func NewNewTransactionBrokerBuilder() *NewTransactionBrokerBuilder {
  15. return &NewTransactionBrokerBuilder{}
  16. }
  17. // @Reference LAPP_GAAS_GFrame_BACKEND/container/CallerBrokerBuilder.Check
  18. func (builder *NewTransactionBrokerBuilder) Check(methodType Method) error {
  19. if methodType == nil {
  20. return errors.New(fmt.Sprintf("方法类型不能为空!"))
  21. }
  22. // 从接口类型获取方法类型,Receiver不算作入参
  23. if methodType.NumIn() < 1 {
  24. return errors.New(fmt.Sprintf("参数太少!实际数量:%d", methodType.NumIn()))
  25. }
  26. if methodType.In(0) != RequestContextType {
  27. return errors.New(fmt.Sprintf("第一个参数必须是*RequestContext"))
  28. }
  29. for i := 1; i < methodType.NumIn(); i++ {
  30. if methodType.In(i) == RequestContextType {
  31. return errors.New(fmt.Sprintf("第%d个参数不能是*RequestContext", i+1))
  32. }
  33. }
  34. return nil
  35. }
  36. // @Reference LAPP_GAAS_GFrame_BACKEND/container/CallerBrokerBuilder.Build
  37. func (builder *NewTransactionBrokerBuilder) Build(sessionContext *SessionContext, caller Caller) (Caller, error) {
  38. if sessionContext == nil {
  39. return nil, errors.New(fmt.Sprintf("会话上下文不能为空!"))
  40. }
  41. if caller == nil {
  42. return nil, errors.New(fmt.Sprintf("调用器不能为空!"))
  43. }
  44. return (&NewTransactionBroker{caller, sessionContext}).Call, nil
  45. }