added get loop and new key type xor

This commit is contained in:
ston1th 2023-03-22 22:52:19 +01:00
commit 9e68b46346
8 changed files with 122 additions and 24 deletions

View file

@ -54,8 +54,14 @@ func (a *Approver) List() (m ApprovalMap) {
}
func (a *Approver) Status(id, aid, ip string) (s Status) {
a.mu.RLock()
if app, ok := a.m[aid]; ok && app.ID == id && app.IP == ip {
s = app.Status
if app, ok := a.m[aid]; ok {
if app.ID == id && app.IP == ip {
s = app.Status
} else {
s = Rejected
}
} else {
s = NotFound
}
a.mu.RUnlock()
if s == Approved || s == Rejected {
@ -66,13 +72,16 @@ func (a *Approver) Status(id, aid, ip string) (s Status) {
return
}
func (a *Approver) Update(aid string, s Status) {
func (a *Approver) Update(aid string, s Status) (err error) {
a.mu.Lock()
if app, ok := a.m[aid]; ok {
app.Status = s
a.m[aid] = app
} else {
err = ErrReqNotFound
}
a.mu.Unlock()
return
}
type Approval struct {
@ -88,6 +97,7 @@ const (
Pending Status = iota
Approved
Rejected
NotFound
)
func (s Status) String() string {
@ -98,6 +108,8 @@ func (s Status) String() string {
return "approved"
case Rejected:
return "rejected"
case NotFound:
return "notfound"
}
return "[invalid]"
}