1 Star 0 Fork 4

jiaoyuedave/Service-Box-go

forked from Plato/Service-Box-go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
box_linux.go 1.94 KB
一键复制 编辑 原始数据 按行查看 历史
CloudGuan 提交于 2022-12-09 09:04 . !4 update: http 网关功能实现
package sbox
import (
"io/fs"
"path/filepath"
"plugin"
"gitee.com/dennis-kk/rpc-go-backend/idlrpc"
"gitee.com/dennis-kk/service-box-go/util/tools"
)
func (sb *ServiceBox) loadAllService() error {
// load service from waitload pack aage
for n, p := range sb.waitLoadPack {
err := sb.loadServiceByPackInfo(p)
if err != nil {
sb.logger.Warn("%s load service from package error !", n)
continue
}
}
sb.waitLoadPack = make(packCache)
// if config service path, load from directory
// FIXME read from config
return sb.loadServiceFromDir("./Debug")
}
func (sb *ServiceBox) loadServiceFromDir(rootPath string) error {
//check file exist
if !tools.IsEffectiveDir(rootPath) {
sb.logger.Warn("no effective shared library storage path")
return nil
}
var bundles []string
err := filepath.Walk(rootPath, func(path string, info fs.FileInfo, err error) error {
if err != nil {
//TODO add error log
return err
}
// skip root path
if path == rootPath {
return nil
}
//skip dir
if info.IsDir() {
return nil
}
if filepath.Ext(path) == ".so" {
bundles = append(bundles, path)
}
return nil
})
if err != nil {
//TODO add err log
return err
}
// open dll and get register function
for _, bundle := range bundles {
open, err := plugin.Open(bundle)
if err != nil {
//TODO add error log
continue
}
varHandle, err := open.Lookup("ServiceUUID")
if err != nil {
continue
}
funcHandle, err := open.Lookup("Creator")
if err != nil {
//TODO add error log
continue
}
//dynamic cast
if regHandle, ok := funcHandle.(idlrpc.SdkCreateHandle); ok {
srvUid := varHandle.(uint64)
srvPack := &idlrpc.PackageInfo{
ServiceUUID: srvUid,
Creator: regHandle,
}
err := sb.loadServiceByPackInfo(srvPack)
if err != nil {
sb.logger.Warn("%s load service lib error %v", bundle, err)
continue
}
sb.logger.Info("%s load service successful", bundle)
}
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jiaoyuedave/service-box-go.git
git@gitee.com:jiaoyuedave/service-box-go.git
jiaoyuedave
service-box-go
Service-Box-go
master

搜索帮助