-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook_store.go
57 lines (43 loc) · 1.03 KB
/
hook_store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2018 The Harbor Authors. All rights reserved.
package opm
import (
"sync"
"github.com/vmware/harbor/src/jobservice/utils"
)
//HookStore is used to cache the hooks in memory.
//Use job ID as key to index
type HookStore struct {
lock *sync.RWMutex
data map[string]string
}
//NewHookStore is to create a ptr of new HookStore.
func NewHookStore() *HookStore {
return &HookStore{
lock: new(sync.RWMutex),
data: make(map[string]string),
}
}
//Add new record
func (hs *HookStore) Add(jobID string, hookURL string) {
if utils.IsEmptyStr(jobID) {
return //do nothing
}
hs.lock.Lock()
defer hs.lock.Unlock()
hs.data[jobID] = hookURL
}
//Get one hook url by job ID
func (hs *HookStore) Get(jobID string) (string, bool) {
hs.lock.RLock()
defer hs.lock.RUnlock()
hookURL, ok := hs.data[jobID]
return hookURL, ok
}
//Remove the specified one
func (hs *HookStore) Remove(jobID string) (string, bool) {
hs.lock.Lock()
defer hs.lock.Unlock()
hookURL, ok := hs.data[jobID]
delete(hs.data, jobID)
return hookURL, ok
}