mirror of
https://github.com/jech/galene.git
synced 2024-11-22 00:25:58 +01:00
Split token.Get into method and function.
This commit is contained in:
parent
368791648f
commit
e8ea707904
1 changed files with 12 additions and 8 deletions
|
@ -57,25 +57,29 @@ func SetStatefulFilename(filename string) {
|
|||
tokens.modTime = time.Time{}
|
||||
}
|
||||
|
||||
// Get fetches a stateful token.
|
||||
// It returns os.ErrNotExist if the token doesn't exist.
|
||||
func Get(token string) (*Stateful, error) {
|
||||
tokens.mu.Lock()
|
||||
defer tokens.mu.Unlock()
|
||||
err := tokens.load()
|
||||
func (state *state) Get(token string) (*Stateful, error) {
|
||||
state.mu.Lock()
|
||||
defer state.mu.Unlock()
|
||||
err := state.load()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tokens.tokens == nil {
|
||||
if state.tokens == nil {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
t := tokens.tokens[token]
|
||||
t := state.tokens[token]
|
||||
if t == nil {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// Get fetches a stateful token.
|
||||
// It returns os.ErrNotExist if the token doesn't exist.
|
||||
func Get(token string) (*Stateful, error) {
|
||||
return tokens.Get(token)
|
||||
}
|
||||
|
||||
func (token *Stateful) Check(host, group string, username *string) (string, []string, error) {
|
||||
if token.Group == "" || group != token.Group {
|
||||
return "", nil, errors.New("token for bad group")
|
||||
|
|
Loading…
Reference in a new issue