33 lines
595 B
Go
33 lines
595 B
Go
package openai
|
|
|
|
import "sync"
|
|
|
|
var (
|
|
maxBlackApikeySize = 5000
|
|
)
|
|
|
|
type BlackkeyMgr struct {
|
|
blackApikey map[string]struct{}
|
|
lock *sync.Mutex
|
|
}
|
|
|
|
var blackKeyMgr = &BlackkeyMgr{blackApikey: make(map[string]struct{}), lock: new(sync.Mutex)}
|
|
|
|
func (b *BlackkeyMgr) AddBlackKey(k string) {
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
if len(b.blackApikey) >= maxBlackApikeySize {
|
|
b.blackApikey = make(map[string]struct{})
|
|
}
|
|
b.blackApikey[k] = struct{}{}
|
|
return
|
|
}
|
|
|
|
func (b *BlackkeyMgr) IsBlack(k string) bool {
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
_, ok := b.blackApikey[k]
|
|
return ok
|
|
}
|