// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com). // All rights reserved. // module-register.go package expr import ( "fmt" ) type module struct { importFunc func(ExprContext) description string imported bool } func newModule(importFunc func(ExprContext), description string) *module { return &module{importFunc, description, false} } var moduleRegister map[string]*module func registerImport(name string, importFunc func(ExprContext), description string) { if moduleRegister == nil { moduleRegister = make(map[string]*module) } if _, exists := moduleRegister[name]; exists { panic(fmt.Errorf("module %q already registered", name)) } moduleRegister[name] = newModule(importFunc, description) } func IterateModules(op func(name, description string, imported bool) bool) { if op != nil { for name, mod := range moduleRegister { if !op(name, mod.description, mod.imported) { break } } } } // ---- func init() { if moduleRegister == nil { moduleRegister = make(map[string]*module) } }