function register
This commit is contained in:
parent
54bc759f70
commit
8ad25afdc4
47
function-register.go
Normal file
47
function-register.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
|
// All rights reserved.
|
||||||
|
|
||||||
|
// function-register.go
|
||||||
|
package expr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
var functionRegister map[string]func(ExprContext)
|
||||||
|
|
||||||
|
func registerImport(name string, importFunc func(ExprContext)) {
|
||||||
|
if functionRegister == nil {
|
||||||
|
functionRegister = make(map[string]func(ExprContext))
|
||||||
|
}
|
||||||
|
functionRegister[name] = importFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
func ImportInContext(ctx ExprContext, name string) (exists bool) {
|
||||||
|
var importFunc func(ExprContext)
|
||||||
|
if importFunc, exists = functionRegister[name]; exists {
|
||||||
|
importFunc(ctx)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func ImportInContextByGlobPattern(ctx ExprContext, pattern string) (count int, err error) {
|
||||||
|
var matched bool
|
||||||
|
for name, importFunc := range functionRegister {
|
||||||
|
if matched, err = filepath.Match(pattern, name); err == nil {
|
||||||
|
if matched {
|
||||||
|
count++
|
||||||
|
importFunc(ctx)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if functionRegister == nil {
|
||||||
|
functionRegister = make(map[string]func(ExprContext))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user