github.com/infraboard/keyauth@v0.8.1/apps/token/session/context.go (about)

     1  package session
     2  
     3  import (
     4  	"github.com/infraboard/keyauth/apps/token"
     5  )
     6  
     7  // NewSession todo
     8  func NewSession() *Session {
     9  	return &Session{}
    10  }
    11  
    12  // Session 请求上下文信息
    13  type Session struct {
    14  	tk *token.Token
    15  }
    16  
    17  // WithToken 携带token
    18  func (s *Session) WithToken(tk *token.Token) {
    19  	s.tk = tk
    20  }
    21  
    22  // WithTokenGetter geter
    23  func (s *Session) WithTokenGetter(gt Getter) {
    24  	s.tk = gt.GetToken()
    25  }
    26  
    27  // GetToken 获取token
    28  func (s *Session) GetToken() *token.Token {
    29  	return s.tk
    30  }
    31  
    32  // GetAccount todo
    33  func (s *Session) GetAccount() string {
    34  	if s.tk == nil {
    35  		return "Nil"
    36  	}
    37  
    38  	return s.tk.Account
    39  }
    40  
    41  // Getter 获取token
    42  type Getter interface {
    43  	GetToken() *token.Token
    44  }