动态加载程序包 [英] Load package dynamically

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

问题描述

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

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天全站免登陆