动态加载包 [英] Load package dynamically

查看:19
本文介绍了动态加载包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在运行时加载特定的包?我想要一种插件,每个插件都具有与其他插件相同的功能但具有不同的行为,并根据配置文件加载一个或另一个.

Is it possible to load a specific package during runtime? I want to have a kind of plugins where each one has the same functions than the others but with different behaviour, and depending on the configuration file, load one or other.

推荐答案

您可以考虑在运行时执行插件"包,通过写出一个新程序(例如,到临时目录)并通过 exec.Command,类似于 exec.Command("go", "run", files...).Run()

You might consider executing the ‘plugin’ packages at runtime, by writing out a new program (say, to a temp directory) and executing via exec.Command, something along the lines of exec.Command("go", "run", files…).Run()

您会在这里看到一些类似的代码.

You’ll see some similar code here.

这篇关于动态加载包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆