auto cleanup reqs

This commit is contained in:
ston1th 2023-03-23 01:43:20 +01:00
commit 84937cc3a1

View file

@ -4,6 +4,7 @@ package types
import (
"sync"
"time"
"git.giftfish.de/ston1th/keyctl/pkg/key"
"golang.org/x/exp/maps"
@ -77,6 +78,7 @@ func (a *Approver) Update(aid string, s Status) (err error) {
if app, ok := a.m[aid]; ok {
app.Status = s
a.m[aid] = app
go a.cleanup(aid)
} else {
err = ErrReqNotFound
}
@ -84,6 +86,13 @@ func (a *Approver) Update(aid string, s Status) (err error) {
return
}
func (a *Approver) cleanup(aid string) {
time.Sleep(time.Second * 10)
a.mu.Lock()
delete(a.m, aid)
a.mu.Unlock()
}
type Approval struct {
ID string
Name string