function-register.go module-register.go
This commit is contained in:
parent
06ab303b9e
commit
6dd8283308
@ -1,25 +1,25 @@
|
|||||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
|
|
||||||
// function-register.go
|
// module-register.go
|
||||||
package expr
|
package expr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
var functionRegister map[string]func(ExprContext)
|
var moduleRegister map[string]func(ExprContext)
|
||||||
|
|
||||||
func registerImport(name string, importFunc func(ExprContext)) {
|
func registerImport(name string, importFunc func(ExprContext)) {
|
||||||
if functionRegister == nil {
|
if moduleRegister == nil {
|
||||||
functionRegister = make(map[string]func(ExprContext))
|
moduleRegister = make(map[string]func(ExprContext))
|
||||||
}
|
}
|
||||||
functionRegister[name] = importFunc
|
moduleRegister[name] = importFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportInContext(ctx ExprContext, name string) (exists bool) {
|
func ImportInContext(ctx ExprContext, name string) (exists bool) {
|
||||||
var importFunc func(ExprContext)
|
var importFunc func(ExprContext)
|
||||||
if importFunc, exists = functionRegister[name]; exists {
|
if importFunc, exists = moduleRegister[name]; exists {
|
||||||
importFunc(ctx)
|
importFunc(ctx)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -27,7 +27,7 @@ func ImportInContext(ctx ExprContext, name string) (exists bool) {
|
|||||||
|
|
||||||
func ImportInContextByGlobPattern(ctx ExprContext, pattern string) (count int, err error) {
|
func ImportInContextByGlobPattern(ctx ExprContext, pattern string) (count int, err error) {
|
||||||
var matched bool
|
var matched bool
|
||||||
for name, importFunc := range functionRegister {
|
for name, importFunc := range moduleRegister {
|
||||||
if matched, err = filepath.Match(pattern, name); err == nil {
|
if matched, err = filepath.Match(pattern, name); err == nil {
|
||||||
if matched {
|
if matched {
|
||||||
count++
|
count++
|
||||||
@ -41,7 +41,7 @@ func ImportInContextByGlobPattern(ctx ExprContext, pattern string) (count int, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if functionRegister == nil {
|
if moduleRegister == nil {
|
||||||
functionRegister = make(map[string]func(ExprContext))
|
moduleRegister = make(map[string]func(ExprContext))
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user