知识卡片
进程内插件动态载入符号
Go原生插件把main包中的导出变量或函数编成共享对象,由宿主Open加载、Lookup查找已知符号,再断言到约定接口使用。插件初次载入会初始化相关包,main不自动执行;它与宿主共享进程,不能靠插件边界隔离崩溃或任意内存行为。
原稿形式:p, err := plugin.Open(path),成功后sym, err := p.Lookup("Sayer"),再检查符号类型。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Loose Coupling · 查看原书依据
A plugin is a Go main package with one or more exported functions and variables that has been built with the -buildmode=plugin build flag. It’s represented in the plugin package by the Plugin type. Open Opening a plugin is the process of loading it into memory, validating it, and discovering its exposed symbols. A plugin
参考来源
- 位置:《Cloud Native Go》第08章《Loose Coupling》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch08.xhtml)
- 结论依据:Go原生插件把main包中的导出变量或函数编成共享对象,由宿主Open加载、Lookup查找已知符号,再断言到约定接口使用。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:A plugin is a Go main package with one or more exported functions and variables that has been built with the -buildmode=plugin build flag. It’s represented in the plugin package by the Plugin type. Open Opening a plugin is the process of loading it into memory, validating it, and discovering its exposed symbols. A plugin