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.

40 lines
943 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. // Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
  2. package container
  3. import (
  4. "errors"
  5. "fmt"
  6. "LEIT_PM/global"
  7. )
  8. // 会话上下文
  9. type SessionContext struct {
  10. // 用户信息
  11. user *global.User
  12. // 事务句柄工厂
  13. transactionHandlerFactory TransactionHandlerFactory
  14. }
  15. // 创建会话上下文
  16. // 参数
  17. // 1.用户标识
  18. // 返回值:
  19. // 1.会话上下文
  20. // 2.错误
  21. func NewSessionContext(user *global.User, transactionHandlerFactory TransactionHandlerFactory) (*SessionContext, error) {
  22. if user == nil {
  23. return nil, errors.New(fmt.Sprintf("用户信息不能为空!"))
  24. }
  25. if transactionHandlerFactory == nil {
  26. return nil, errors.New(fmt.Sprintf("事务句柄工厂不能为空!"))
  27. }
  28. return &SessionContext{user, transactionHandlerFactory}, nil
  29. }
  30. // 获取用户标识
  31. // 返回值:
  32. // 1.用户信息
  33. func (context *SessionContext) User() *global.User {
  34. return context.user
  35. }