init
Some checks failed
Build and Release / release (push) Failing after 26s

This commit is contained in:
2025-12-12 17:37:34 +07:00
commit 9d769ed08c
32 changed files with 895 additions and 0 deletions

37
cache.go Normal file
View File

@@ -0,0 +1,37 @@
package main
import (
"crypto/tls"
"sync"
)
type CertStorage struct {
certs map[string]*tls.Certificate
mtx sync.RWMutex
}
func (cs *CertStorage) Fetch(hostname string, gen func() (*tls.Certificate, error)) (*tls.Certificate, error) {
cs.mtx.RLock()
cert, ok := cs.certs[hostname]
cs.mtx.RUnlock()
if ok {
return cert, nil
}
cert, err := gen()
if err != nil {
return nil, err
}
cs.mtx.Lock()
cs.certs[hostname] = cert
cs.mtx.Unlock()
return cert, nil
}
func NewCertStorage() *CertStorage {
return &CertStorage{
certs: make(map[string]*tls.Certificate),
}
}