nuclei/pkg/js/gojs/set.go
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

31 lines
833 B
Go

package gojs
import (
"github.com/dop251/goja"
errorutil "github.com/projectdiscovery/utils/errors"
)
var (
ErrInvalidFuncOpts = errorutil.NewWithFmt("invalid function options: %v")
)
type FuncOpts struct {
Name string
Signatures []string
Description string
FuncDecl interface{}
}
// valid checks if the function options are valid
func (f *FuncOpts) valid() bool {
return f.Name != "" && f.FuncDecl != nil && len(f.Signatures) > 0 && f.Description != ""
}
// RegisterFunc registers a function with given name, signatures and description
func RegisterFuncWithSignature(runtime *goja.Runtime, opts FuncOpts) error {
if !opts.valid() {
return ErrInvalidFuncOpts.Msgf("name: %s, signatures: %v, description: %s", opts.Name, opts.Signatures, opts.Description)
}
return runtime.Set(opts.Name, opts.FuncDecl)
}