Chore: cleanup code

This commit is contained in:
yaling888
2022-07-01 18:34:36 +08:00
parent e1fe8ce3b2
commit ae6cc1d67d
25 changed files with 159 additions and 189 deletions

View File

@@ -2,6 +2,7 @@ package cert
import (
"crypto/tls"
"sync"
"github.com/Dreamacro/clash/component/trie"
)
@@ -9,10 +10,14 @@ import (
// DomainTrieCertsStorage cache wildcard certificates
type DomainTrieCertsStorage struct {
certsCache *trie.DomainTrie[*tls.Certificate]
lock sync.RWMutex
}
// Get gets the certificate from the storage
func (c *DomainTrieCertsStorage) Get(key string) (*tls.Certificate, bool) {
c.lock.RLock()
defer c.lock.RUnlock()
ca := c.certsCache.Search(key)
if ca == nil {
return nil, false
@@ -22,7 +27,9 @@ func (c *DomainTrieCertsStorage) Get(key string) (*tls.Certificate, bool) {
// Set saves the certificate to the storage
func (c *DomainTrieCertsStorage) Set(key string, cert *tls.Certificate) {
c.lock.Lock()
_ = c.certsCache.Insert(key, cert)
c.lock.Unlock()
}
func NewDomainTrieCertsStorage() *DomainTrieCertsStorage {