From e73aaa31d720746f1108de195b17f51e1ba70150 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sun, 9 Jul 2023 11:51:18 +0200 Subject: [PATCH] Remove tokens.Del. It was unused. --- token/stateful.go | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/token/stateful.go b/token/stateful.go index 854324e..a43dd13 100644 --- a/token/stateful.go +++ b/token/stateful.go @@ -215,29 +215,18 @@ func Add(token *Stateful) (*Stateful, error) { return tokens.Add(token) } -func (state *state) Del(group, token string) error { - tokens.mu.Lock() - defer tokens.mu.Unlock() - _, err := state.edit(group, token, nil) - return err -} - -func Del(group, token string) error { - return tokens.Del(group, token) +func Edit(group, token string, expires time.Time) (*Stateful, error) { + return tokens.Edit(group, token, expires) } func (state *state) Edit(group, token string, expires time.Time) (*Stateful, error) { tokens.mu.Lock() defer tokens.mu.Unlock() - return state.edit(group, token, &expires) -} - -func Edit(group, token string, expires time.Time) (*Stateful, error) { - return tokens.Edit(group, token, expires) + return state.edit(group, token, expires) } // called locked -func (state *state) edit(group, token string, expires *time.Time) (*Stateful, error) { +func (state *state) edit(group, token string, expires time.Time) (*Stateful, error) { err := state.load() if err != nil { return nil, err @@ -254,14 +243,11 @@ func (state *state) edit(group, token string, expires *time.Time) (*Stateful, er if old.Group != group { return nil, os.ErrPermission } - var new *Stateful - if expires.Equal(time.Time{}) { - delete(state.tokens, token) - } else { - new = old.Clone() - new.Expires = expires - state.tokens[token] = new - } + + new := old.Clone() + new.Expires = &expires + state.tokens[token] = new + err = state.rewrite() if err != nil { state.tokens[token] = old