Tarun Koyalwar dc44105baf
nuclei v3 : misc updates (#4247)
* use parsed options while signing

* update project layout to v3

* fix .gitignore

* remove example template

* misc updates

* bump tlsx version

* hide template sig warning with env

* js: retain value while using log

* fix nil pointer derefernce

* misc doc update

---------

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
2023-10-17 17:44:13 +05:30

40 lines
924 B
Go

package cache
import (
"sync"
)
// Templates is a cache for caching and storing templates for reuse.
type Templates struct {
items *sync.Map
}
// New returns a new templates cache
func New() *Templates {
return &Templates{items: &sync.Map{}}
}
type parsedTemplateErrHolder struct {
template interface{}
err error
}
// Has returns true if the cache has a template. The template
// is returned along with any errors if found.
func (t *Templates) Has(template string) (interface{}, error) {
value, ok := t.items.Load(template)
if !ok || value == nil {
return nil, nil
}
templateError, ok := value.(parsedTemplateErrHolder)
if !ok {
return nil, nil
}
return templateError.template, templateError.err
}
// Store stores a template with data and error
func (t *Templates) Store(template string, data interface{}, err error) {
t.items.Store(template, parsedTemplateErrHolder{template: data, err: err})
}