1
Fork 0
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:
Juliusz Chroboczek 2024-05-01 19:29:30 +02:00
parent 368791648f
commit e8ea707904

View file

@ -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")