feat: 添加resolve方法解析dns,关闭script规则需要解析IP
This commit is contained in:
34
component/js/script.go
Normal file
34
component/js/script.go
Normal file
@@ -0,0 +1,34 @@
|
||||
//go:build !no_script
|
||||
|
||||
package js
|
||||
|
||||
import (
|
||||
"github.com/dop251/goja"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var JS sync.Map
|
||||
var mux sync.Mutex
|
||||
|
||||
func NewJS(name, code string) error {
|
||||
program, err := compiler(name, code)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, ok := JS.Load(name); !ok {
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
if _, ok := JS.Load(name); !ok {
|
||||
JS.Store(name, program)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Run(name string, args map[string]any, callback func(any, error)) {
|
||||
if value, ok := JS.Load(name); ok {
|
||||
run(getLoop(), value.(*goja.Program), args, callback)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user