goProject/.svn/pristine/c0/c0a839d663b36c1a3dd52beeaada9454b05cff52.svn-base
2025-01-06 16:21:36 +08:00

68 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package printMgr
import (
"fmt"
"sync"
. "Framework/startMgr"
)
var (
funcMap = make(map[string]*FuncItem)
mutex sync.Mutex
)
// 注册方法(如果名称重复会panic)
// name:方法名称(唯一标识)
// moduleType:模块类型
// definition:方法定义
func Register(name string, moduleType ModuleType, definition func() error) {
mutex.Lock()
defer mutex.Unlock()
if _, exists := funcMap[name]; exists {
panic(fmt.Sprintf("%s已经存在请重新命名", name))
}
funcMap[name] = NewFuncItem(name, moduleType, definition)
}
// 调用所有方法
// 返回值:
// 错误列表
func CallAll() (errList []error) {
mutex.Lock()
defer mutex.Unlock()
for _, item := range funcMap {
// 调用方法
if err := item.Call(); err != nil {
errList = append(errList, err)
}
}
return
}
// 按照模块类型进行调用
// moduleType:模块类型
// 返回值:
// errList:错误列表
func CallType(moduleType ModuleType) (errList []error) {
mutex.Lock()
defer mutex.Unlock()
for _, item := range funcMap {
if item.ModuleType != moduleType {
continue
}
// 调用方法
if err := item.Call(); err != nil {
errList = append(errList, err)
}
}
return
}