package disk12import (3"io"4"io/fs"5"os"67"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"8)910// DiskCatalog is a template catalog helper implementation based on disk11type DiskCatalog struct {12templatesDirectory string13templatesFS fs.FS // Due to issues with how Go has implemented fs.FS, we'll have to also implement normal os operations, as well. See: https://github.com/golang/go/issues/4427914}1516// NewCatalog creates a new Catalog structure using provided input items17// using disk based items18func NewCatalog(directory string) *DiskCatalog {19catalog := &DiskCatalog{templatesDirectory: directory}20if directory == "" {21catalog.templatesDirectory = config.DefaultConfig.GetTemplateDir()22}23return catalog24}2526// NewFSCatalog creates a new Catalog structure using provided input items27// using the fs.FS as its filesystem.28func NewFSCatalog(fs fs.FS, directory string) *DiskCatalog {29catalog := &DiskCatalog{30templatesDirectory: directory,31templatesFS: fs,32}33return catalog34}3536// OpenFile opens a file and returns an io.ReadCloser to the file.37// It is used to read template and payload files based on catalog responses.38func (d *DiskCatalog) OpenFile(filename string) (io.ReadCloser, error) {39if d.templatesFS == nil {40return os.Open(filename)41}4243return d.templatesFS.Open(filename)44}454647