ai-css/library/modelprovider/providers/openai/blackkeys.go
2026-02-12 08:50:11 +00:00

33 lines
595 B
Go
Executable File

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
}